Notifications

Installation

iOS SDK support's notificaiton sending. It uses Firebase messaging system to send the notifications. Before one can use GSD framework to respond to notifications one hase to register his app on the Firebase server. The full installation instruction is available here.

To be able to respond to the notifications inside a project, one has to import Firebase module into his pod file, and then install the pod.

Example:

1
2
3
4
5
target <Project_Name> do
    pod 'GSDMobileFramework', :git => 'http://akaleta@gsd-web-02/sdk/iOS/GSDMobileFramework.git’, :branch  => 'Develop'
    pod 'Firebase/Core'
    pod 'Firebase/Messaging'
end

Usage

To be able to use the full functionalities of GSDFramework one has to use GSDRemoteNotificationsService class. It is responsiblefor handling the standard DOCUframe notifications, and also gives the possibility to handle custom user notifications.

Inside the AppDelegate one has to implement:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    Messaging.messaging().delegate = self
    if #available(iOS 10.0, *) {
        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = GSDRemoteNotificationsService.sharedInstance

        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()
}

The line below is responsible for passing the controll over the notification system to GSDFramework. UNUserNotificationCenter.current().delegate = GSDRemoteNotificationsService.sharedInstance

Also the user wil have to modify another AppDelegate function:

1
2
3
4
5
6
7
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Messaging.messaging().shouldEstablishDirectChannel = true
    Messaging.messaging().apnsToken = deviceToken

    let token = Messaging.messaging().fcmToken
    GSDRemoteNotificationsService.sharedInstance.didRefreshRegistrationToken(fcmToken: token!)
}

After succesfull registration for notifications, the SDK will automatically store the notification key, and will try to update the information inside the DOCUframe database. Thank's to that, the DOCUframe database will be able to send the notifications to this specific device.

Recieving the response

To be able to respond to the notifications one has to register his object to special delegate protocol GSDRemoteNotificationServiceDelegate.

Example:

1
GSDRemoteNotificationsService.sharedInstance.delegate = myObject;

After recieving the notification which is not handled by default (for example alert notification), the special method of this delegate will be called, and the developer will be able to decide what to do with it.

Example:

1
2
3
func didRecieveAlert(alert:[String:String]) {
    print(alert)
}