Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

In order to enable push notifications using UrbanAirship, the SDK provided by UrbanAirship is to be integrated within the Mobile app that requires it. The SDK can be integrated using various methods e.g. Cocoapods, classic etc. The exact steps to setup the SDK are specified in detail on the website http://docs.urbanairship.com/platform/ios.html

The UrbanAirship SDK supports the new rich notifications provided by iOS 10+ as well as provides support for the previous versions as well. Depending on the target framework, the relevant instructions can be followed on the link provided previously.

Before the notifications can be retrieved on the mobile device, its important to generate the necessary certificates using the instructions provided at http://docs.urbanairship.com/reference/push-providers/apns.html#ios-apns-setup

Once the notifications are correctly setup and the UrbanAirship services are started, we can retrieve the DeviceToken and the ChannelID which would eventually be used to target push notifications for individual devices. Once this DeviceToken is retrieved successfully, it needs to be registered with Rubiq API so push notifications can be sent out using Rubiq Platform using UrbanAirship SDK. Please note that that in order to push notifications using API, the MasterKey and AppKey are required, which can be accessed from the UrbanAirship App dashboard.


A sample AppDelegate file is as follows.


AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, UARegistrationDelegate, UAPushNotificationDelegate {

    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
        
        let config = UAConfig.default()
        UAirship.takeOff(config)
        
        UAirship.push().notificationOptions = [.alert, .badge, .sound]
        UAirship.push().userPushNotificationsEnabled = true
        
        UAirship.push().registrationDelegate = self
        UAirship.push().pushNotificationDelegate = self
        
        return true
    }
    
    func registrationSucceeded(forChannelID channelID: String, deviceToken: String) {
        print("Registration succeeded. ChannelID: \(channelID), DeviceToken: \(deviceToken)")

        // TODO: Register DeviceID with RubiqAPI
    }

    func receivedForegroundNotification(_ notificationContent: UANotificationContent, completionHandler: @escaping () -> Void) {
        print("Received foreground notification. DeviceToken: \(UAirship.push().deviceToken)")
        
    }
    
    @available(iOS 10.0, *)
    func presentationOptions(for notification: UNNotification) -> UNNotificationPresentationOptions {
        print("Presentation options")
        return [.alert, .sound]
    }
    
    func receivedBackgroundNotification(_ notificationContent: UANotificationContent, completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        print("Received background notification. DeviceToken: \(UAirship.push().deviceToken)")
    }
}



  • No labels