我正在做這個需要推送通知的甜美應用程序。註冊推送通知功能不會被調用
但是,當試圖抓取Push令牌時,並不是所有必需的函數都被執行。
用戶不會得到跟此警報:
當用戶點擊OK我通過我的代碼退一步,看到不是一切被執行:
override func viewDidLoad(){
let tapper = UITapGestureRecognizer(target: view, action:#selector(UIView.endEditing))
tapper.cancelsTouchesInView = false
view.addGestureRecognizer(tapper)
print("gets called")
registerForPushNotifications(UIApplication.sharedApplication())
}
func registerForPushNotifications(application: UIApplication) {
print("gets called")
let notificationSettings = UIUserNotificationSettings(
forTypes: [.Badge, .Sound, .Alert], categories: nil)
application.registerUserNotificationSettings(notificationSettings)
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
print("doesn't get called")
if notificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
print("doesn't get called")
let tokenChars = UnsafePointer<CChar>(deviceToken.bytes)
var apnsTokenString = ""
for i in 0..<deviceToken.length {
apnsTokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]])
}
Constant.pushToken = apnsTokenString
print("Device Token:", Constant.pushToken)
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
debugPrint("Error Registering Remote Notification")
}
在我的控制檯打印如下:
被稱爲
被稱爲
含義,並不是所有需要的功能調用。我究竟做錯了什麼?
沒有調用didRegisterForRemoteNotificationsWithDeviceToken func的權利?請參閱此鏈接 - http://stackoverflow.com/questions/39490605/push-notification-issue-with-ios-10/39506524#39506524 –
不,那個不會被叫。這正是我需要調用的功能。 –
好吧,按照這個鏈接中給出的步驟 - http://stackoverflow.com/questions/39490605/push-notification-issue-with-ios-10/39506524#39506524 –