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

Bhargav Soni picture Bhargav Soni · Oct 4, 2016 · Viewed 8.2k times · Source

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!

Answer

Bhargav Soni picture Bhargav Soni · Oct 4, 2016

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

#import <UserNotifications/UserNotifications.h>