Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

how to activate the ios notification settings programmatically?

My app registers for the notifications like this :

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 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.

UPDATE as of iOS 8.0

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...