8

Czy ktoś może mi pomóc w realizacji powiadomienia push dla iOS 10 jakom realizowany następujący kod, ale wciąż się problem w tym:Jak zaimplementować powiadomienia push dla systemu iOS 10 [Objective C]?

#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 
} 

otrzymuję błąd sugerując, że

nieznane odbiornik UIUserNotificationCenter

Z góry dziękuję!

+0

zobaczyć http://stackoverflow.com/questions/39382852/didreceiveremotenotification-not-called-ios-10/39383027 # 39383027 –

Odpowiedz

25

Przepraszam, mam odpowiedź. Po prostu potrzebowałem do importowania struktury UserNotifications.

#import <UserNotifications/UserNotifications.h> 
0

Sprawdź to

#import <UserNotifications/UserNotifications.h> 

Następnie

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { 
     UIUserNotificationType allNotificationTypes = 
     (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); 
     UIUserNotificationSettings *settings = 
     [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; 
     [application registerUserNotificationSettings:settings]; 
    } else { 
     // iOS 10 or later 
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 
     // For iOS 10 display notification (sent via APNS) 
     [UNUserNotificationCenter currentNotificationCenter].delegate = self; 
     UNAuthorizationOptions authOptions = 
     UNAuthorizationOptionAlert 
     | UNAuthorizationOptionSound 
     | UNAuthorizationOptionBadge; 
     [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) { 
     }]; 
#endif 
    } 
Powiązane problemy