An open API service indexing awesome lists of open source software.

https://github.com/infobip/poc-mobile-messaging-spm

Proof of concept of Mobile Messaging iOS SDK with Swift Package support. Only InAppChat and WebRTCUI are included. Not for production use.
https://github.com/infobip/poc-mobile-messaging-spm

Last synced: 2 months ago
JSON representation

Proof of concept of Mobile Messaging iOS SDK with Swift Package support. Only InAppChat and WebRTCUI are included. Not for production use.

Awesome Lists containing this project

README

        

DEPRECATED: SPM is now officially supported by Infobip Mobile Messaging SDK. This POC repository is obsolete and will be soon removed.

# Mobile Messaging SDK for iOS

[![Version](https://img.shields.io/cocoapods/v/MobileMessaging.svg?style=flat)](http://cocoapods.org/pods/MobileMessaging)
[![License](https://img.shields.io/cocoapods/l/MobileMessaging.svg?style=flat)](http://cocoapods.org/pods/MobileMessaging)
[![Platform](https://img.shields.io/cocoapods/p/MobileMessaging.svg?style=flat)](http://cocoapods.org/pods/MobileMessaging)

Mobile Messaging SDK is designed and developed to easily enable push notification channel in your mobile application. In almost no time of implementation you get push notification in your application and access to the features of Infobip Mobile Apps Messaging. The document describes library integration steps. Additional information can be found in our Wiki.

## Requirements
- Xcode 13.2.1+
- Swift 4.2, Swift 5
- iOS 12.0+

## Quick start guide
This guide is designed to get you up and running with Mobile Messaging SDK integrated into your iOS application.

1. Make sure to setup application at Infobip portal, if you haven't already.

2. Configure your project to support Push Notifications:
1. Click on "Capabilities", then turn on Push Notifications. Entitlements file should be automatically created by Xcode with set `aps-environment` value.
Enable Push Notifications capability

2. Turn on Background Modes and check the Remote notifications checkbox.
Enable Remote Notifications in Background Modes settings

3. Import all targets from https://github.com/infobip/poc-mobile-messaging-spm (MobileMessaging, InAppChat and WebRTCUI):

4. Import the library into your AppDelegate file:

```swift
import MobileMessaging
import WebRTCUI
import InAppChat
```

5. Start MobileMessaging service using your Infobip Application Code, obtained in step 1, and preferable notification type as parameters:

```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
MobileMessaging.withApplicationCode(<#your application code#>, notificationType: <#for example MMUserNotificationType(options: [.alert, .sound])#>)?.start()
...
}
```

In case you already use other Push Notifications vendor's SDK, add `withoutRegisteringForRemoteNotifications()` to the start call:

```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
MobileMessaging.withApplicationCode(<#your application code#>, notificationType: <#for example MMUserNotificationType(options: [.alert, .sound])#>)?.withoutRegisteringForRemoteNotifications()?.start()
...
}
```

Please note that it is not very secure to keep your API key (Application Code is an API key in fact) hardcoded so if the security is a crucial aspect, consider obfuscating the Application Code string (we can recommend UAObfuscatedString for string obfuscation).

6. Add one line of code `MobileMessaging.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken)` to your AppDelegate method `application:didRegisterForRemoteNotificationsWithDeviceToken:` in order to inform Infobip about the new device registered:

```swift
// Swift
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
MobileMessaging.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken)

// other push vendors might have their code here and handle a Device Token as well
}
```

7. Add one line of code `MobileMessaging.didReceiveRemoteNotification(userInfo, fetchCompletionHandler: completionHandler)` to your AppDelegate method `application:didReceiveRemoteNotification:fetchCompletionHandler:` in order to send notification's delivery reports to Infobip:

```swift
// Swift
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
MobileMessaging.didReceiveRemoteNotification(userInfo, fetchCompletionHandler: completionHandler)

// other push vendors might have their code here and handle a remove notification as well
}
```

8. [Integrate Notification Service Extension](https://github.com/infobip/mobile-messaging-sdk-ios/wiki/Notification-Service-Extension-for-Rich-Notifications-and-better-delivery-reporting-on-iOS-10) into your app in order to obtain:
- more accurate processing of messages and delivery stats
- support of rich notifications on the lock screen



In case of a clean project, your AppDelegate.swift code should look like following:
AppDelegate source code example

If all the steps implemented correctly, run your application on a real device, you should see the logs in Xcode console confirming that the MobileMessaging SDK has been initialized succesfully and the device has been registered on APNS to receive Push messages:
```
2023-01-28 18:24:16:003 [MobileMessaging] ℹ️ SDK successfully initialized!
...
2023-01-28 18:25:44:144 [MobileMessaging] ℹ️ [APNS reg manager] Application did register with device token <...>
```
If you don't see any logs, set up the default logger before starting the SDK: `MobileMessaging.logger = MMDefaultLogger()`. Please note that the logs are only collected while your project is in "debug" configuration.

**Please pay close attention to a Provisioning Profile that is used for your project build. It must match the APNs environment! If they don't, we'll invalidate the device push registration (more information here [I don't receive push notifications!](https://github.com/infobip/mobile-messaging-sdk-ios/wiki/I-don't-receive-push-notifications)**

> #### Notice
> Push notifications (if they are not [in-app](https://github.com/infobip/mobile-messaging-sdk-ios/wiki/In-app-notifications)) are not displayed automatically when the app is on the foreground. For further information check [FAQ - How to display messages when app is running in the foreground?](https://github.com/infobip/mobile-messaging-sdk-ios/wiki/How-to-display-messages-when-app-is-running-in-the-foreground%3F).



NEXT STEPS: User profile





| If you have any questions or suggestions, feel free to send an email to [email protected] or create an issue. |
|---|