我在Xcode 7.3中實現了蘋果推送通知演示應用程序。它工作正常。最近我下載了Xcode 8.現在我的演示程序在Xcode 7和Xcode 8中都不起作用。委託方法沒有被調用。我不知道,出了什麼問題。 Xcode建議創建權利,我做到了。請任何人幫助我。推送通知代理方法沒有在Xcode 8.2.1中調用
感謝, Vikash
我在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的設備上工作。 –