0

How to turn On Off Notificiation form app with using component UISwitch. From setting if user turn On/Off Notification of any specific application UISwitch is turn On/Off using

 [[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");
        }
    }
}

This above code work fine when user turn On/Off Notification from IPhone setting.

How to implement from application to turn On/Off Notification which is in IPhone setting?

Note: This is for LocalNotification not for PushNotification!

kiran
  • 4,285
  • 7
  • 53
  • 98
  • Possible duplicate of [How to enable/disable push notification from the app?](https://stackoverflow.com/questions/13814651/how-to-enable-disable-push-notification-from-the-app) – Surbhi Garg May 25 '18 at 05:19

1 Answers1

0

You can't do that due to apple restrictions it doesn't matter if its local or push notification:

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

mohammad_Z74
  • 244
  • 2
  • 10