Local notifications not working for some users (iOS 8)

后端 未结 3 1813
北海茫月
北海茫月 2021-01-02 10:11

I have an app which uses local notifications and ti used to work fine in previous versions. I have updated the app for iOS 8 and tested and worked fine. After submitting the

相关标签:
3条回答
  • 2021-01-02 10:17

    Try this for Objective-C:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
    {
    // are you running on iOS8?
    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) 
      {
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil];
        [application registerUserNotificationSettings:settings];
      } 
    else // iOS 7 or earlier
      {
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [application registerForRemoteNotificationTypes:myTypes];
      }
    }
    

    For Swift:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    // Override point for customization after application launch.
     if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:")))
     {
        application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
     }
     else
     {
        //
     }
    return true
    }
    
    0 讨论(0)
  • 2021-01-02 10:18
    void EnableLocalNotificationIOS8
    {
        UIApplication *app = [UIApplication sharedApplication];
    
        if ([app respondsToSelector:@selector(registerUserNotificationSettings:)])
        {
            UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
            [app registerUserNotificationSettings:settings];
            [app registerForRemoteNotifications];
        }
    }
    
    0 讨论(0)
  • 2021-01-02 10:36

    First You have to Register to Use Local Push Notification

    UIApplication *application = [UIApplication sharedApplication];
    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    }
    

    then you can send Local Push Notification By This

     UILocalNotification *notification = [UILocalNotification new];
    notification.alertBody = @"Local Push !!!";
    notification.applicationIconBadgeNumber=1;
    [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
    
    0 讨论(0)
提交回复
热议问题