detect notification center setting
My app needs to be set in iOS 5 Notification C开发者_StackOverflow中文版enter as 'alerts' and with 'sounds' on. From what I have found it is not possible for your app to offer setting these correctly, which would be the best option so correct me if im wrong.
So, I am looking for a procedure to detect the current settings and warn the user if these are not correct.
actually it can be done with the following method -
UIRemoteNotificationType types = [UIApplicationsharedApplication].enabledRemoteNotificationTypes;
while types is
typedef enum
{
UIRemoteNotificationTypeNone = 0,
UIRemoteNotificationTypeBadge = 1 << 0,
UIRemoteNotificationTypeSound = 1 << 1,
UIRemoteNotificationTypeAlert = 1 << 2,
UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3
}
according to:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html
So if you want to know if the user approved your app for notifications, all you need to do is to check whether types >= 4
be aware: this will not tell you if the user has enabled or disabled notification center for your app, it will only tell you the TYPE of the notification that the user approved
This cannot be done programmatically. And "registerForRemoteNotificationTypes" is for remote (push) notifications, not local ones.
The only thing I have been able to do is include in my app description on the app store an explanation on how to set up the Notification Center. I also put it in my demonstration video.
You may also think about putting in a prompt the first time the app is launched explaining the "correct" notification settings for your app. Don't show it on subsequent launches, but have it available in a "help" section.
Sure, "what is correct" is what the user wants, but for my app, the users have NEVER wanted the default settings, which is "banners". The best user experience for my app is "sounds" only. The biggest complaint about my app before Notification Center was the pop ups from the local notifications. Now, with Notification Center, users can turn off everything except for "sounds". That is the setting that they all seem to want. Why can't I as a developer just give it to them as the default? If they want to change it to something else, that's great, but I should have control over the default settings. But I'm ranting.
I don't think this can be done programmatically.
You can stipulate though what alerts your app can accept when launched.
I would use this in the app delegate, didFinishLaunchingWithOptions method
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
Think of it this way: what would you, as a user, think if every other app set these on? (Sure, you want it on for your app. But not all apps are good like yours.) Or, if every other app warned you every time it launched?
Not possible, and that's why.
Like Nik said, just put up everything you hope the user will enable. The system will then give the user a chance to allow this.
精彩评论