2015-12-14 3 views
0

Привет, в моем приложении у меня есть секция уведомлений, и пользователь может активировать уведомления с помощью переключателя. После первого запуска, когда пользователь на коммутаторе, который я получаю, не разрешает или не предупреждает пользователя ios. Если пользователь не разрешает, а переключатель отключается, а пользователь не будет получать уведомления. Теперь, если пользователь попытается переключиться на переключатель, я хочу показать предупреждение пользователю с текстом «Пожалуйста, включите оповещения из настроек». Укажите любой способ предложить это.Оповестить пользователя о включении уведомлений из настроек в ios

ответ

0

Вы можете проверить разрешение с помощью метода isRegisteredForRemoteNotifications.

- (void)checkForNotificationPermission 
{ 
    if (!([[UIApplication sharedApplication] isRegisteredForRemoteNotifications] && [self pushNotificationsEnabled])) 
    { 
     // Show alert here 
    } 
} 


// For fixing iOS 8 issue mentioned here http://stackoverflow.com/a/28441181/1104384 
- (BOOL)pushNotificationsEnabled 
{ 
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) 
    { 
     UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types]; 
     return (types & UIUserNotificationTypeAlert); 
    } 
    else 
    { 
     UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 
     return (types & UIRemoteNotificationTypeAlert); 
    } 
} 
0

Для UILocalNotification проверки разрешения ниже, types значение параметра будет ни упаковывают пользователь не не позволил.

[[UIApplication sharedApplication] currentUserNotificationSettings] 
0
NSString *iOSversion = [[UIDevice currentDevice] systemVersion]; 
      NSString *prefix = [[iOSversion componentsSeparatedByString:@"."] firstObject]; 
      float versionVal = [prefix floatValue]; 


      if (versionVal >= 8) 
      { 
       if ([[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone) 
       { 

        NSLog(@" Push Notification ON"); 
       } 
       else 
       { 

        NSString *msg = @"Please press ON to enable Push Notification"; 
        UIAlertView *alert_push = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Setting", nil]; 
        alert_push.tag = 2; 
        [alert_push show]; 

        NSLog(@" Push Notification OFF"); 

       } 

      } 
      else 
      { 
       UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 
       if (types != UIRemoteNotificationTypeNone) 

       { 
        NSLog(@" Push Notification ON"); 

       } 
       else 
       { 
        NSString *msg = @"Please press ON to enable Push Notification"; 
        UIAlertView *alert_push = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Setting", nil]; 
        alert_push.tag = 2; 
        [alert_push show]; 

        NSLog(@" Push Notification OFF"); 
       } 

      } 
0
 UIUserNotificationType allNotificationTypes = 
     (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); 

     UIUserNotificationSettings *settings = 
     [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; 
     [[UIAp 

пликация sharedApplication] registerUserNotificationSettings: Настройки];

// [[UIApplicationsharedApplication] registerForRemoteNotifications];

 if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) { 


      UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types]; 

      if (types == UIUserNotificationTypeNone) { 



      [_TransparentView setBackgroundColor:[[UIColor clearColor] colorWithAlphaComponent:0.8]]; 


       [email protected]"Please enable notifications from settings."; 
      } 

     } 
    } 
0

Пробуйте этот код. Он будет работать для iOS 8.0 позже и до версий.

if (([[[UIDevice currentDevice] systemVersion] compare:8.0 options:NSNumericSearch] != NSOrderedAscending)) { 
    if (![[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) 
    { 
     DisplayAlert(@"Please enable Permission from Settings->App Name->Notifications->Allow Notifications"); 
     return; 
    } 
} 
else{ 
    UIRemoteNotificationType status = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 
    if (status == UIRemoteNotificationTypeNone) 
    { 
     DisplayAlert(@"Please enable Permission from Settings->App Name->Notifications->Allow Notifications"); 
     return; 
    } 
} 
Смежные вопросы