iOS Native SDK Setup

Steps for setting up your iOS app with iZooto app push

Step 1: Requirements

  • Your iZooto App ID. You can find it under Settings in your account.
  • An iOS device (iPhone, iPad, iPod Touch) to test on. The Xcode simulator doesn't support push notifications so you must test on a real device.
  • A Mac with a new version of Xcode.
  • An iOS Push Certificate.


Step 2: Add a Notification Extension Service

The iZootoNotificationExtendsServices allows your iOS application to receive rich notifications with images, buttons, and badges.

2.1 In Xcode Select File > New > Target
2.2 Select Notification Service Extension then press Next.

2.3. Enter the product name as iZootoNotificationExtendsServices and press Finish.

2.4. In the project navigator, select the top-level project directory and select the iZootoNotificationExtendsServices target in the project and targets list.

Unless you have a specific reason not to, you must set the Deployment Target to be iOS 10.

2.5. Open NotificationService.swift (NotificationService.m for Objective C))under iZootoNotificationExtendsServices and replace the entire file's contents with the following code.

import UserNotifications
import iZootoiOSSDK
class NotificationService: UNNotificationServiceExtension {
  var contentHandler: ((UNNotificationContent) -> Void)?
  var bestAttemptContent: UNMutableNotificationContent?
  var receivedRequest: UNNotificationRequest!
  override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
    print("Response",request)
      self.receivedRequest = request;
      self.contentHandler = contentHandler
      bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
      if let bestAttemptContent = bestAttemptContent {
        iZooto.didReceiveNotificationExtensionRequest(bundleName :"YOUR_BUNDLE_IDENTIFIER_NAME",request: receivedRequest, bestAttemptContent: bestAttemptContent,contentHandler: contentHandler)       
    }
    }
    override func serviceExtensionTimeWillExpire() {
      if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
        contentHandler(bestAttemptContent)
      }
    }
}
#import "NotificationService.h"
 
@interface NotificationService ()
 
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
 
@end
 
@implementation NotificationService
 
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.receivedRequest = request;
    self.bestAttemptContent = [request.content mutableCopy];
    if (self.bestAttemptContent != nil)
    {
      [iZooto didReceiveNotificationExtensionRequestWithBundleName:@"YOUR_BUNDLE_IDENTIFIER_NAME" request:self.receivedRequest bestAttemptContent:self.bestAttemptContent contentHandler: self.contentHandler];
    }
   // self.contentHandler(self.bestAttemptContent);
}
 
- (void)serviceExtensionTimeWillExpire {
    // Called just before the extension will be terminated by the system.
    // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
    self.contentHandler(self.bestAttemptContent);
}
 
@end
#import <UserNotifications/UserNotifications.h>
 
@import iZootoiOSSDK;
 
@interface NotificationService : UNNotificationServiceExtension
 
@end

Ignore any build errors at this point, step 2 will import iZooto which will resolve any errors.



Step 3: Import the iZooto SDK into your Xcode project

These instructions are for CocoaPods, the most common way to manage dependencies for Xcode Projects.

3.1. Make sure your current Xcode project is closed and in the project root, open terminal and, run
sudo gem install cocoapods
3.2. Run pod init from the terminal in your project directory.
3.3. Open the newly created Podfile with your favorite code editor such as Sublime or type open Podfile from the terminal in your project directory.
3.4. Add the iZooto dependency under your project name target

use_frameworks!
target 'your_project_name' do
 //only copy below line
  pod 'iZootoiOSSDK'
 
target 'iZootoNotificationExtendsServices' do
  //only copy below line
  pod 'iZootoiOSSDK'

end
end

3.5. Run the following commands in your terminal in your project directory.
pod repo update
pod install

Open the newly created .xcworkspace file.

Make sure to always open the workspace from now on. You can also do this automatically by running xed .** from the root of your project.



Step 4: Add Required Capabilities

This step will make sure your project is able to receive remote notifications.

Only do this for the main application target.
Do not do this for the Notification Service Extension.

4.1. Select the root project, your main app target, and "Signing & Capabilities".
4.2. Select "All", then under "Background Modes" check "Remote notifications". You should see Push Notifications already provided.

4.3. If you do not see Push Notifications enabled, click "+ Capability" and double click "Push Notifications" to add it.



Step 5: Add the iZooto Initialization Code

Navigate to your AppDelegate file and add the iZooto initialization code to didFinishLaunchingWithOptions.
We would also be introducing additional methods.

Make sure to import the iZooto header

import UIKit
import iZootoiOSSDK

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, iZootoNotificationOpenDelegate, iZootoNotificationReceiveDelegate, iZootoLandingURLDelegate {
  // handle deeplink
  func onNotificationOpen(action: Dictionary<String, Any>) {
    print(action)
  }
  
  // Handle url
  func onHandleLandingURL(url: String) {
    // setlandingURL
    print("ClickURL",url)
  }
  
  // Notification Received
  func onNotificationReceived(payload: Payload) {
    print("Payload",payload.alert?.body! as Any )
  }
  
  var i = 0
  var window: UIWindow?
  
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // for setting
    let iZootoInitSettings = ["auto_prompt": true,"nativeWebview": true, "provisionalAuthorization":false]
    iZooto.initialisation(izooto_id: "<your_iZooto_app_id>", application: application, iZootoInitSettings:iZootoInitSettings)
    
    UNUserNotificationCenter.current().delegate = self
    iZooto.notificationOpenDelegate = self
    iZooto.notificationReceivedDelegate = self
    iZooto.landingURLDelegate = self
      return true
  }
  
  func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    iZooto.getToken(deviceToken: deviceToken)
  }
  
  @available(iOS 10.0, *)
  func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)     {
    iZooto.handleForeGroundNotification(notification: notification, displayNotification: "None", completionHandler: completionHandler)
  }
  
  // @available(iOS 10.0, *)
  func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    iZooto.notificationHandler(response: response) //iZooto.notificationHandler
    completionHandler()
  }
}
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@import iZootoiOSSDK;
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate,iZootoLandingURLDelegate,iZootoNotificationOpenDelegate,iZootoNotificationReceiveDelegate>
@property (strong, nonatomic) UIWindow * window;
@property(nonatomic, weak)id <iZootoLandingURLDelegate> landingURLDelegate;
@property(nonatomic, weak)id <iZootoNotificationOpenDelegate> notificationOpenDelegate;
@property(nonatomic, weak)id <iZootoNotificationReceiveDelegate> notificationReceivedDelegate;
@end
#import "AppDelegate.h"
@import iZootoiOSSDK;
@import UserNotifications;
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  dispatch_async(dispatch_get_main_queue(), ^{
//define settings
    NSMutableDictionary *izootoInitSetting = [[NSMutableDictionary alloc]init];
    [izootoInitSetting setObject:@YES forKey:@"auto_prompt"];
    [izootoInitSetting setObject:@NO forKey:@"nativeWebview"];
    [izootoInitSetting setObject:@NO forKey:@"provisionalAuthorization"];
  // initalise the iZooto SDK
    [iZooto initialisationWithIzooto_id:@"<iZooto_id_here>" application:application iZootoInitSettings:izootoInitSetting];
        iZooto.notificationReceivedDelegate = self;
        iZooto.landingURLDelegate = self;
        iZooto.notificationOpenDelegate = self;  
  });
  return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  //Get Token from When enbale prompt allow
  [iZooto getTokenWithDeviceToken:deviceToken];
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
  NSLog(@"Received");
  [iZooto handleForeGroundNotificationWithNotification:notification displayNotification:@"NONE" completionHandler:completionHandler];
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
     withCompletionHandler:(void (^)(void))completionHandler
{
  [iZooto notificationHandlerWithResponse:response];
  completionHandler();
}
- (void)onHandleLandingURLWithUrl:(NSString * _Nonnull)url {
}
- (void)onNotificationOpenWithAction:(NSDictionary<NSString *,id> * _Nonnull)action {
  NSLog(@"NSString = %@", action);
}
- (void)onNotificationReceivedWithPayload:(Payload * _Nonnull)payload {
  NSLog(@"NSString = %@",payload);
}
@end

❗️

Replace YOUR_iZooto_APP_ID with your iZooto ID.
This can be found under the Settings of your iOS Project on iZooto.



Step 6: Add Internet permission in your XCode Project.

Go to Info.plist right click Open As > Source Code. Add following lines after < /array > tag.

For Internet Permissions

<key>NSAppTransportSecurity</key>
    <dict>
            <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>


Step 7: Run your app on a device and send yourself a notification.

Test your app on a physical iOS device to make sure it builds correctly. You should be prompted to subscribe to notifications and you should be able to send yourself a notification from the iZooto dashboard.

❗️

Make sure that you have configured APNS certificate corresponding to you iOS Project on iZooto.

Click here for a guide.

Note that the iOS Simulator does not support receiving remote push notifications.

👍

Done! You have successfully integrated iZooto's iOS SDK with your application.

If you need any assistance during onboarding, reach out to us at [email protected]



Step 8: Customize what your app does when a notification is clicked or received (Optional)

Notification Handlers

NotificationReceivedHandler - This will be called when a notification is received.

NotificationOpenedHandler - This will be called when a notification is tapped on.


Did this page help you?