8

사람은 내가 구현으로 아이폰 OS (10)에 대한 푸시 알림을 구현하는 코드를 다음하지만 여전히 그 안에 문제를지고 나를 도와 드릴까요 : 그iOS 용 푸시 알림 구현 방법 10 [목표 C]?

알 수없는 수신기 UIUserNotificationCenter

제안 오류를 얻고있다

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

미리 감사드립니다.

+0

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

답변

25

죄송합니다. 답변을 얻었습니다. 방금 ​​UserNotifications 프레임 워크를 가져와야합니다.

#import <UserNotifications/UserNotifications.h> 
0

확인이 그런

#import <UserNotifications/UserNotifications.h> 

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 
    }