问题
How to detect local(not push notification) notifications are allowed or not ? I'm going to integrate local notifications with my app, and for app functionality is very important to detect are local notifications allowed or not.
回答1:
Local notifications are always allowed and are available as any other functionality in iOS SDK. Push notifications, however, require special signature for the app to work. Read more about that in Developer docs.
If your app is frontmost and requires to respond to local notification, just implement method application:didReceiveLocalNotification:
If it's not, then implement functionality, that is described in Apple Developer docs in method application:didFinishLaunchingWithOptions:
回答2:
As I know user can not disable local notification. So, you do not need to check availability of them.
回答3:
Use CLLocationManager Delegate if user not allow location service the delegate call:
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error;
And when the notification service allow you can use local notification whit this function:
- (void)startMonitoringForRegion:(CLRegion *)region
desiredAccuracy:(CLLocationAccuracy)accuracy __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA, __MAC_NA,__IPHONE_4_0, __IPHONE_6_0);
来源:https://stackoverflow.com/questions/21181519/determine-if-local-notification-is-allowed