在我的入职申请中,我有一个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