I want to check "Push Notification option" in iOS device, any time if the application is running (or ON from resume mode). I use the following code to check, if the option is OFF:
-(void)PushNotificationServiceChecking
{
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone)
{
NSString *msg = @"Please press ON to enable Push Notification";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"ON", nil];
alert.tag = 2;
[alert show];
}
}
Then i use the following code for going to the "Settings tab >> Notification center", so that user can on it manually :
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 2)
{
if (buttonIndex == 0)
{
// this is the cancel button
}
else if (buttonIndex == 1)
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert)];
}
}
}
But, now the problem that I am facing is, it only appears at the 1st time after launching the application. It works as I want. But after that, if I turn OFF the "Push Notification option" from "settings" it gives me no "Alert Message".
registerForRemoteNotification
, it couldn't detect the "Push Notification option" is ON or OFF second time. How can i detect that every time, if my application is running. That's the problem. Thanks for commenting. @Kumar Ki – Fairman