Manual Integration in Swift
    • 2 Minutes to read
    • Dark
      Light

    Manual Integration in Swift

    • Dark
      Light

    Article summary

    Goal

    Manually integrate the Mapp SDK into your iOS app using Swift.

    Note:

    • This guide covers manual integration for advanced users who need greater customization.

    • For basic integration, see the Basic Automated Setup.

    Prerequisites

    Before beginning, ensure:

    1. Xcode Requirements:

      • Base SDK: iOS 10 or higher.

      • Deployment Target: iOS 8 or higher.

    2. Appoxee Account:

      • An account on the Appoxee dashboard with a configured application.

    Procedure

    1. Download the SDK

    2. Add the SDK to Your Project: Drag AppoxeeSDK.framework or AppoxeeSDK.xcframework into your project.

    3. Import the SDK: Add the following to your Objective-C bridging header if using Swift:

      #import <AppoxeeSDK/AppoxeeSDK.h>
    4. Set Up Delegates: Declare the AppDelegate class with the following:

      class AppDelegate: UIResponder, UIApplicationDelegate, AppoxeeNotificationDelegate {
          // Class implementation
      }
    5. Configure didFinishLaunchingWithOptions: Add the initialization code in the application:didFinishLaunchingWithOptions: method:

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

      The parameter with represents enum SERVER that enables you to choose one of the four options: L3, EMC, L3_US, EMC_US.

      The account manager will provide you with the info on which one you should use in your application.

    6. Handle Notifications: Implement the following methods:

      • Register for Notifications:

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

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

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

      • Push Actions for iOS 8: Add the following for handling action identifiers:

        func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject: AnyObject], completionHandler: () -> Void) {
            let handled = Appoxee.shared()?.handleActionWithIdentifier(identifier, forRemoteNotification: userInfo, completionHandler: completionHandler)
            if !handled {
                completionHandler()
            }
        }
      • Custom Push Notification Categories:

        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
        }
    8. Silent Push (Optional): Refer to the SDK documentation for implementing silent pushes.

      func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
          Appoxee.shared()?.receivedRemoteNotification(userInfo)
          completionHandler(.newData)
      }
    9. Appoxee Delegate (Optional): Handle custom push actions by implementing:

      func appoxee(appoxee: Appoxee, handledRemoteNotification pushNotification: APXPushNotification, andIdentifer actionIdentifier: String) {
          // Handle the custom push action
      }


    Was this article helpful?