出于某种原因,我的iOS应用程序之间有几分钟的延迟 registerForRemoteNotifications和didRegisterForRemoteNotificationsWithDeviceToken
有时多达5分钟 任何想法为什么会这样?
extension AppDelegate: UNUserNotificationCenterDelegate {
func requestPushNotification() {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.currentNotificationCenter().delegate = self
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([UNAuthorizationOptions.Alert, UNAuthorizationOptions.Sound, UNAuthorizationOptions.Badge]) { (success, error) in
if success {
//UIApplication.sharedApplication().registerForRemoteNotifications()
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
} else {
if error != nil {
Crashlytics.sharedInstance().recordError(error!)
}
}
}
} else {
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
//UIApplication.sharedApplication().registerForRemoteNotifications()
}
}
@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
print("willPresentNotification")
}
@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
print("didReceiveNotificationResponse")
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
if notificationSettings.types != UIUserNotificationType() {
application.registerForRemoteNotifications()
}
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
Crashlytics.sharedInstance().recordError(error)
print(error)
}
}
和
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
}
任何想法都将不胜感激