Search code examples
iosobjective-cpush-notificationappdelegatensusernotification

How to implement push notification for iOS 10[Objective C]?


Can anyone help me with implementing push notification for iOS 10 as i have implemented following code but still getting problem in it:

#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0"))
{
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
        if(!error){
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
    }];
}
else {
    // Code for old versions
}

I am getting error suggesting that

Unknown receiver UIUserNotificationCenter

Thank you in advance!


Solution

  • Sorry guys, I got the answer. I just needed to import UserNotifications framework.

    #import <UserNotifications/UserNotifications.h>