2015-12-14 27 views
0

嗨在我的應用程序我有通知部分,用戶可以啓用通知使用switch.After第一次啓動時,當用戶在交換機上我越來越不允許或從ios的alertview。如果用戶選擇不允許,切換將關閉,用戶將不會收到通知。現在,如果用戶嘗試在交換機上顯示提醒,請向用戶發送文字「請啓用設置通知」。任何人都可以提出建議。警報用戶啓用通知從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; 
    } 
}