如何打开关闭应用程序的通知反映到iPhone设置

时间:2018-05-24 19:49:26

标签: ios objective-c notifications uilocalnotification

如何使用组件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!

1 个答案:

答案 0 :(得分:0)

由于苹果的限制,你无法做到这一点,如果它的本地或推送通知并不重要:

https://stackoverflow.com/a/10510610/8873550