如何以编程方式激活 ios 通知设置? [英] how to activate the ios notification settings programmatically?

查看:29
本文介绍了如何以编程方式激活 ios 通知设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序注册这样的通知:

My app registers for the notifications like this :

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];

但如果我手动转到通知设置,禁用所有内容(通知中心、警报、声音、徽章)然后卸载并重新安装应用程序(或直接重新安装而不先卸载),我的 iPhone 会保留旧设置.如何在重新安装时强制重新激活这些设置?

but if I manually go to the notifications settings, disable everything (notification center, alert, sound, badge) then uninstall and reinstall the app (or just reinstall without uninstalling first), my iPhone keeps the old settings. How can I force to reactivate these settings back on reinstallation?

推荐答案

你不能.在 iOS 5.0 中,有一个未记录的功能可以通过 url 方案从您的应用程序打开通知设置页面(或任何设置页面).然后您可以要求用户启用通知.但它在 5.1 中被删除了,无论如何可能不会被 Apple 接受.

You can't. In iOS 5.0 there was a not documented feature to open the notification setting page (or any setting page) from your application via an url scheme. Then you could ask the user to enable the notifications. But it was removed in 5.1 and anyway probably would not be accepted by Apple.

registerForRemoteNotificationTypes 询问用户他是否希望仅在您第一次调用您的应用程序时接受来自您的应用程序的通知.如果稍后用户更改了通知设置,则它不会再询问它.您可以使用 enabledRemoteNotificationTypes 检查您的应用程序是否启用了通知,并根据需要自行警告用户,但用户必须手动转到设置并重新启用它们.您不能再通过您的应用程序执行此操作.

registerForRemoteNotificationTypes asks the user whether he wants to accept notifications from your application only the first time you call it. If later the user changes the notification settings then it will not ask it again any more. You can check whether notifications are enabled for your application with enabledRemoteNotificationTypes and warn the user yourself if you want, but user will have to go manually to the settings and re-enable them. You can't do it any more from your application.

从 iOS 8.0 开始更新

从 iOS 8.0 开始,Apple 恢复了打开应用的系统设置页面的可能性:

From iOS 8.0 Apple returned the possibility to open the System Settings page of your app:

NSURL* settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsURL];

这篇关于如何以编程方式激活 ios 通知设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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