如何使用组件UISwitch打开“关闭通知”表单应用程序。 从设置是否打开/关闭任何特定应用程序的通知UISwitch使用
打开/关闭 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnteredForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
- (void)applicationEnteredForeground:(NSNotification *)notification {
NSLog(@"Application Entered Foreground");
[self notificationEnableDisable];
}
-(void)notificationEnableDisable{
NSString *iOSversion = [[UIDevice currentDevice] systemVersion];
NSString *prefix = [[iOSversion componentsSeparatedByString:@"."] firstObject];
float versionVal = [prefix floatValue];
if (versionVal >= 8)
{
if ([[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone)
{
NSLog(@" Notification ON");
[self.switch_DailyNotification setOn:YES];
}
else
{
[self.switch_DailyNotification setOn:NO];
NSLog(@" Notification OFF");
}
}
else
{
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types != UIRemoteNotificationTypeNone)
{
NSLog(@"Notification ON");
[self.switch_DailyNotification setOn:YES];
}
else
{
[self.switch_DailyNotification setOn:NO];
NSLog(@" Notification OFF");
}
}
}
当用户从iPhone设置打开/关闭通知时,上面的代码正常工作。
如何从应用程序实现打开/关闭iPhone设置中的通知?
注意:这适用于LocalNotification,不适用于PushNotification!