답변

1

당신은 넣을 수 있습니다 : 당신의 IBAction 내부

let center = UNUserNotificationCenter.current() 
    center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in 
     // Enable or disable features based on authorization. 
    } 
    UIApplication.shared.registerForRemoteNotifications() // you can also set here for local notification. 

UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; 
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound) 
         completionHandler:^(BOOL granted, NSError * _Nullable error) { 
          // Enable or disable features based on authorization. 
         }]; 
[[UIApplication sharedApplication] registerForRemoteNotifications]; // you can also set here for local notification. 

스위프트

목표 - C. Capabilities - - Push notification

당신이 IBAction을 가지고 Push Notificationtarget에서 활성화되어 있는지 확인하십시오 경우 파일에 목표 - C에 대한 스위프트 또는 #import <UserNotifications/UserNotifications.h>에 대한 import UserNotifications를 추가도 기억하시기 바랍니다.

0

목표 - C :

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { 
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; 
} 
+0

'UIUserNotificationSettings'가 아이폰 OS 10에서 더 이상 사용되지 않습니다 당신은 UNNotificationSettings' 대신'사용한다. https://developer.apple.com/documentation/uikit/uiusernotificationsettings – Mateusz

관련 문제