本地通知是否需要iOS上的用户权限? [英] Do Local Notifications need user permission on iOS?

查看:94
本文介绍了本地通知是否需要iOS上的用户权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用UILocalNotification来安排通知.通知可以正常运行,并在我希望它们显示时显示.我对此没有问题.我没有做任何远程/推送通知.

I am using UILocalNotification in my app to schedule notifications. The notifications work fine and show up when I want them to. I dont have an issue with that. I am NOT doing any remote/push notifications.

让我感到奇怪的是,我从未见过您通常在几个应用程序中看到的有关推送通知的著名权限对话框.我什至重置了设备并运行了我的应用程序.但这仍然没有导致权限对话框出现.

What got me wondering is that I never saw the famous permissions dialog that you usually see for push notifications in several app. I even reset my device and ran my app. That still didn't cause the permission dialog to show up.

如果您的应用仅使用本地通知,或者我没有实现某种实际上导致应用请求此许可的方法,此许可对话框是否不会显示?

Does this permission dialog not show up if your app is using only local notifications or am I not implementing some method that actually causes the app to ask for this permission?

我知道在应用程序启动后,我可以执行自己的对话框,要求用户提供此权限,但我希望Apple能够做到这一点,特别是因为它在设置"应用程序中将远程通知和本地通知视为相同.

I know I could implement my own dialog after the app started that asked the user for this permission but I was hoping that Apple took care of that, especially since it treats remote and local notifications the same in the Settings app.

推荐答案

注意:这包括推送通知/远程通知

NOTE: this includes push notifications / remote notifications

在iOS7或iOS8上使用Xcode6时测试registerUserNotificationSettings:API在运行时是否可用.

when using Xcode6 with iOS7 or iOS8 Test when registerUserNotificationSettings: API is available at runtime.

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {  
    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];  
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];  
    [[UIApplication sharedApplication] registerForRemoteNotifications];  
} else {  
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];  
}  

感谢 http://corinnekrych.blogspot.ae/2014/07/how-to-support-push-notification-for.html

这篇关于本地通知是否需要iOS上的用户权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆