推送通知代理方法没有在Xcode 8.2.1中调用
我在Xcode 7.3中实现了苹果推送通知演示应用程序。它工作正常。最近我下载了Xcode 8.现在我的演示程序在Xcode 7和Xcode 8中都不起作用。委托方法没有被调用。我不知道,出了什么问题。 Xcode建议创建权利,我做到了。请任何人帮助我。推送通知代理方法没有在Xcode 8.2.1中调用
感谢, Vikash
推送通知,能力和BuildPhase 在AppDelegate中添加UserNotification工作框架添加委托方法UNUserNotificationCenterDelegate
import UserNotifications
在didFinishingLaunching ...
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) {
}
'didRegisterForRemoteNotificationsWithDeviceToken' - 此委托方法未调用。我在其他帖子中试过这个。但它不适合我,我的部署目标是9.3。 – vikash1307
你有没有从功能推送通知?并添加UNUserNotificationCenterDelegate在应用程序代理 –
雅我也这样做。它曾经赢得过。现在与Xcode 8,我没有得到任何代表电话。 – vikash1307
关于功能的推送通知.. –
它与iOS 10一起工作,但不适用于iOS 9.3.2。 – vikash1307
将部署目标从iOS 10,Xcode 8设置为9,它将在具有iOS 9的设备上工作。 –