嗨,我是新的iOS應用程序開發。我正在使用Swift 3.0代碼。我們可以通過檢查isRegisteredForLocalNotifications更新ViewRegister從didRegisterForRemoteNotificationsWithDeviceToken
在我的應用程序中,我正在獲取設備令牌,並傳遞給我的服務器。將令牌值從Appdelegate傳遞給我使用UserDefaults.standard的UIViewController。它工作正常。在第一次應用程序加載期間,我顯示了系統的推送通知提示。如果用戶單擊確定(允許)或不允許。應用程序使用以下代碼檢查它。
//Checking Notification State
let isRegisteredForLocalNotifications = UIApplication.shared.currentUserNotificationSettings?.types.contains(UIUserNotificationType.alert) ?? false
if isRegisteredForLocalNotifications{
print("Notification allow")
}else{
print("Notification Don't allow")
}
注意:上述代碼在didRegisterForRemoteNotificationsWithDeviceToken中正常工作。
我對上面的代碼有以下問題。
1)如果我在ViewController中使用相同的代碼,它的工作,但我的應用程序不等待系統的推送通知提示結果。我在AppDelegate中獲得結果。
因此如何從didRegisterForRemoteNotificationsWithDeviceToken重新加載ViewController?有沒有辦法做到這一點。
2)我可以暫停viewController,直到用戶響應系統的推送通知提示。但我不確定上面的代碼會在ViewController中工作與否。
請指教。 感謝您的幫助。