Push notification registeration

Its easy to use like native push notification register, we just involve new function inside native ios push notification function.

Prerequisites

  • Installing SDK

Registeration

  • More information about notification register app you can find in this link:- https://developer.apple.com/notifications/

  • to be updated for every change for apple in every version.

Steps to follow

  • Enble push notification

    Capablities -> Push Notifications -> ON
    
  • add following function here

1-

    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //MARK: setting for push notification
    if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
        if(!error){

            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];
            });
        }
        }];
    }
    else {

        UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes  categories:nil];
        [application registerUserNotificationSettings:settings];
        [application registerForRemoteNotifications];

        }
}

2-

- (void)registerApplicationForPushNotifications:(UIApplication *)application
    {
    // Set up push notifications
    // For more information about Push, check out:
    // https://developer.layer.com/docs/ios/guides#push-notification

    // Checking if app is running iOS 8
    if ([application respondsToSelector:@selector(registerForRemoteNotifications)]) {
        // Register device for iOS8
        UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        [application registerUserNotificationSettings:notificationSettings];
        [application registerForRemoteNotifications];
    } else {
    // Register device for iOS7
    [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge];
    }

}

3-

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{

    [AppGain RegisterDeviceWithToken: deviceToken];

    //swift
    AppGain.registerDevice(withToken: deviceToken)
    }

4- for receive remote notification you need to add both of two method so you can track your notificationn open.

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
        ///that call notification track automatic inside it whit status that is opened.
        //objective-c
            [AppGain handlePush:userInfo forApplication:application];
        //swift
            AppGain.handlePush(userInfo, for: application)
            }

5-

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

///that call notification track automatic inside it whit status that is opened.
    [AppGain handlePush:userInfo forApplication:application];
    }