Swift3 在Xcode 8.2.1中未调用推送通知委托方法
我在Xcode 7.3中实现了苹果推送通知演示应用程序。它工作得很好。最近我下载了Xcode 8。现在,我的演示应用程序在Xcode 7和Xcode 8中都无法工作。未调用委托方法。我不知道出了什么问题。Xcode建议创建权利,我做了。请任何人帮帮我 谢谢,Swift3 在Xcode 8.2.1中未调用推送通知委托方法,swift3,ios9,xcode8.2,Swift3,Ios9,Xcode8.2,我在Xcode 7.3中实现了苹果推送通知演示应用程序。它工作得很好。最近我下载了Xcode 8。现在,我的演示应用程序在Xcode 7和Xcode 8中都无法工作。未调用委托方法。我不知道出了什么问题。Xcode建议创建权利,我做了。请任何人帮帮我 谢谢, Vikash从功能推送通知,并在构建阶段添加用户通知框架 在AppDelegate中添加委托方法UNUserNotificationCenterDelegate import UserNotifications 在最后一刻 if #
Vikash从功能推送通知,并在构建阶段添加用户通知框架 在AppDelegate中添加委托方法UNUserNotificationCenterDelegate
import UserNotifications
在最后一刻
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
if error == nil{
UIApplication.shared.registerForRemoteNotifications()
}
}
} else {
// Fallback on earlier versions
}
添加这些方法
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
print(deviceTokenString)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("i am not available in simulator \(error)")
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
}
来自capabilities的推送通知。它正在使用iOS 10。但不适用于iOS 9.3.2。请将部署目标从iOS 10的Xcode 8设置为9,它将在使用iOS 9的设备上工作。我只是这样做了。“DidRegisterForremotentificationsWithDeviceToken”-未调用此委托方法。我在其他帖子上试过了。但它对我不起作用,我的部署目标是9.3。您有来自功能的推送通知吗?在应用程序delegateya中添加UnuseNotificationCenterDelegate我也这么做了。这是以前的事。现在使用Xcode 8,我没有收到任何委托调用。add,UNUserNotificationCenterDelegate in app delegate我也尝试过。但代表并没有接到电话。我不知道为什么?