Push Notifications

Implement push notification in ios 10.

  • Add the following method in “didFinishLaunchingWithOptions” method of application.
notifyvisitors.registerPush(withDelegate: self, app: application, launchOptions: launchOptions)
[notifyvisitors RegisterPushWithDelegate:self App:application launchOptions:launchOptions];
  • Add the following methods inside your App Delegate file to handle the registering and receiving events of push notification.
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { notifyvisitors.DidRegisteredNotification(application, deviceToken: deviceToken)                }
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
print("push register failed due to the following error = \(error)" )
 }
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        notifyvisitors.didReceiveRemoteNotification(userInfo: userInfo)
}
-(void)application: (UIApplication*) application didRegisterForRemoteNotificationsWithDeviceToken: (NSData *)deviceToken  { 

                [notifyvisitors DidRegisteredNotification:application deviceToken:deviceToken]; 
}        

-(void)application: (UIApplication*)application didFailToRegisterForRemoteNotificationsWithError: (NSError *)error { 
           
                NSLog(@"Error:%@",error);              
}               

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

                [notifyvisitors didReceiveRemoteNotificationWithUserInfo:userInfo];  
}
  • For iOS 10 Push Notification, Add the following Delegate Methods in App Delegate file.

a.) Go to AppDelegate.h and import User Notifications framework.

import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

}
#import <UserNotifications/UserNotifications.h>
         @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>         @end

b.) Go to AppDelegate.m file and add the following delegate methods :

@available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        notifyvisitors.willPresent(notification, withCompletionHandler: completionHandler)
    }
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        notifyvisitors.didReceiveRemoteNotification(userInfo, fetchCompletionHandler: completionHandler)
    }
@available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        notifyvisitors.didReceive(response)
    }
# pragma mark UNNotificationCenter Delegate Methods
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {  
        
                [notifyvisitors willPresentNotification:notification withCompletionHandler:completionHandler];       
}       

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {  
  
          [notifyvisitors didReceiveNotificationResponse:response];
}       

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {  
          [notifyvisitors didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];            
}

c.) Add [Notification Service Extension] to support Rich media Attachment in iOS 10 push

notification. Kindly refer to our Notification Service Extension creation guide.

Notification Center

You can show a list of received push notifications in an In-app Notification Center. Expiry of the notifications can be set from the panel.

To launch In-app notification center you can use the following method :

notifyvisitors.NotifyVisitorsNotificationCentre()
[notifyvisitors NotifyVisitorsNotificationCentre];

Geo-fencing

  • To handle the geofencing notifications in background state and Inactive state of application, add the following codes in “applicationDidEnterBackground” and “applicationDidBecomeActive” methods respectively.
- (void)applicationDidEnterBackground:(UIApplication *)application {
  
            [notifyvisitors NotifyVisitorsGeofencingApplicationDidEnterBackground];   
}       

- (void)applicationDidBecomeActive:(UIApplication *)application {  
       
            [notifyvisitors NotifyVisitorsGeofencingapplicationDidBecomeActive];   
}
  • Add the following Code to receive local notification when geofencing events trigger.
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *) notification {  
      [notifyvisitors NotifyVisitorsGeofencingReceivedNotificationWithApplication:application window:self.window didReceiveGeofencingNotification:notification];                                 }