Option 2 - Manual Integration In iOS App - Swift


Goal

To add the SDK to your apps code by manual integration, preform the following steps.

Attention

This topic covers a manual method that gives you greater control, and lets you override behaviour. For an automatic (basic)  process, see iOS SDK Basic Automatic Integration for Mapp Cloud 

Prerequisites

  • Xcode application with a base SDK of iOS 10 and above.
  • Xcode application with a deployment target of iOS 8 and above.
  • An account on the Appoxee dashboard with a configured application.

Procedure

1. Download the SDK from Mapp Cloud Mobile Integration

2. Drag AppoxeeSDK.framework into you project, or see link Integrate Mobile Push SDK for iOS (Mapp Cloud)  

3. Add the following import statement to your Objective-C bridging header

#import <AppoxeeSDK/AppoxeeSDK.h>


If you are adding AppoxeeSDK.xcframework import statement need to look like this:

#import AppoxeeSDK.h"



4. Add the following delegate notation:

class AppDelegate: UIResponder, UIApplicationDelegate, AppoxeeNotificationDelegate {

	/* Class code goes here */
}


5. Add the following implementation to the method named: application:didFinishLaunchingWithOptions:, Where, xxx.xxx represents the SDK ID. These were created for you with the Appoxee Dashboard:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
    Appoxee.shared()?.engageWithLaunchOptions(launchOptions, andDelegate: nil, andSDKID: "123456789.00", with: .L3)
    
    return true
}

For description of parameter with, see the this.

6. Add the following implementation to the method named: application:didRegisterForRemoteNotificationsWithDeviceToken:

 func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {        
	Appoxee.shared()?.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken)
}


7. Add the following implementation to the method named: application:didReceiveRemoteNotification:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        Appoxee.shared()?.receivedRemoteNotification(userInfo)
      }


8. Add the following implementation to the method named: application:didRegisterUserNotificationSettings (deprecated method -  will be updated with new version of SDK):

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
    
    Appoxee.shared()?.didRegisterUserNotificationSettings(notificationSettings)
}


9. OPTIONAL STEP -  To implement iOS8 'Push Actions', add the following implementation to the method named: application:handleActionWithIdentifier:forRemoteNotification:completionHandler:

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
    
    // Must be implemented in order to enable 'Push Actions'.
    let handled = Appoxee.shared()?.handleActionWithIdentifier(identifier, forRemoteNotification: userInfo, completionHandler: completionHandler)
    
    if handled == false {
        
        completionHandler(); // Handle the action in case it is not handled by Appoxee. When done - completionHandler() must be called.
    }
}


10. OPTIONAL STEP – Silent push

Please review the documentation provided with the SDK for the below methods :

application:handleActionWithIdentifier:forRemoteNotification:responseInfo:completionHandler:
application:didReceiveRemoteNotification:fetchCompletionHandler:


11. OPTIONAL STEP - Appoxee delegate:

#pragma mark - AppoxeeDelegate
func appoxee(appoxee: Appoxee, handledRemoteNotification pushNotification: APXPushNotification, andIdentifer actionIdentifier: String) {
    
    // a push notification was recieved.
}


12. OPTIONAL STEP - Add custom push notification category

Code sample
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
	UNUserNotificationCenter.current().delegate = self

	UNUserNotificationCenter.current().requestAuthorization(: [.alert, .badge, .sound], completionHandler: {_, _ in })
	application.registerForRemoteNotifications()

	let CUSTOM_ACTION1 = UNNotificationAction(identifier: "view_now", title: "CUSTOM_ACTION_TITLE", options: .foreground)

	let CUSTOM_ACTION2 = UNNotificationAction(identifier: "skip", title: "CUSTOM_ACTION2_TITLE", options: .foreground)

	let CUSTOM_CATEGORY = UNNotificationCategory(identifier: " CUSTOM_CATEGORY_NAME", actions: [CUSTOM_ACTION1, CUSTOM_ACTION2], intentIdentifiers: [], 						  		hiddenPreviewsBodyPlaceholder: "", options: .customDismissAction)

	let notificationCenter = UNUserNotificationCenter.current()
	notificationCenter.setNotificationCategories([CUSTOM_CATEGORY])
        
	Appoxee.shared()?.saveUserNotificationCategory([CUSTOM_CATEGORY])    

    Appoxee.shared()?.engageWithLaunchOptions(launchOptions, andDelegate: nil, andSDKID: "123456789.00", with: .L3)
    
    return true
}