在我的入職申請中,我有一個UIPageViewController
,其中包含一個用於授權通知的「引導」屏幕。用戶將點擊一個標籤爲「啓用通知」的按鈕,並出現通知權限對話框。我該如何做到這一點?如何在IBAction中要求通知許可?
0
A
回答
1
你可以把:
Objective-C的
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
// Enable or disable features based on authorization.
}];
[[UIApplication sharedApplication] registerForRemoteNotifications]; // you can also set here for local notification.
斯威夫特
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
UIApplication.shared.registerForRemoteNotifications() // you can also set here for local notification.
您IBAction
內。
請記住也在文件中添加import UserNotifications
爲斯威夫特或#import <UserNotifications/UserNotifications.h>
爲Objective-C的,你必須IBAction
,並確保Push Notification
下target
激活 - Capabilities
- Push notification
。
0
的Objective-C:
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
相關問題
- 1. 如何時通知服務站要求
- 2. CDDL許可證要求
- 3. 不能要求READ_EXTERNAL_STORAGE許可
- 4. 不要求麥克許可
- 5. 的網頁通知雲消息傳遞解決方案不要求許可
- 6. Azure中VMRole的SSIS許可證要求
- 7. 主 - 詳細信息:如何通知,要求在Android的重裝
- 8. 蘋果推送通知服務 - 許多通知要發送
- 9. 如何獲取Firebase雲消息傳遞的註冊令牌而不要求獲得通知許可?
- 10. 核心位置不斷要求許可
- 11. webrtc:不要求麥克許可
- 12. 如何檢測Windows防火牆是否要求用戶許可
- 13. 推送通知要求的Android的iOS
- 14. 通知要求的問題和Ruby
- 15. 推送通知如何工作,它的要求是什麼?
- 16. 我可以要求用戶啓用推送通知嗎?
- 17. 第一次啓動時如何防止通知許可?
- 18. 如何向服務請求許可
- 19. iPhone如果允許通知,如何知道用戶選擇
- 20. 如何通過IBAction傳遞對象?
- 21. 可變的IBAction
- 22. 如何知道用戶在推送通知中點擊「不允許」
- 23. 如何通過GAS知道請求IP?
- 24. 如何刪除邀請請求通知?
- 25. 請求WRITE_EXTERNAL_STORAGE許可
- 26. 通知中心 - 如何知道是否存在「未讀」通知?
- 27. C#HttpWebRequest的許多要求
- 28. 如何在IBAction中實現NSArray方法?
- 29. PhoneGap地理位置在iPhone上要求兩次許可權
- 30. Google在使用Play-Authenticate登錄時一直要求許可
'UIUserNotificationSettings'在iOS的10已經過時,你應該使用'UNNotificationSettings'代替。 https://developer.apple.com/documentation/uikit/uiusernotificationsettings – Mateusz