UILocalNotification not working properly

后端 未结 2 1934
误落风尘
误落风尘 2021-01-07 15:10

This is my code.is there anything that i have to add for the localNotification.? Any suggestions. Thanks in advance. I read lots of local notification tutorials. I have no i

相关标签:
2条回答
  • 2021-01-07 15:18

    The Swift way would be like this:

    UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, categories: nil))
    

    update: Xcode 7 • Swift 2.0

    UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert , .Sound, .Badge], categories: nil))
    
    0 讨论(0)
  • 2021-01-07 15:33

    From the Local and Remote Notification Programming Guide:

    In iOS 8 and later, apps that use either local or remote notifications must register the types of notifications they intend to deliver. The system then gives the user the ability to limit the types of notifications your app displays. The system does not badge icons, display alert messages, or play alert sounds if any of these notification types are not enabled for your app, even if they are specified in the notification payload.

    As shown in the guide, the sample code that Apple shows is:

        UIUserNotificationType types = UIUserNotificationTypeBadge |
                 UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
    
    UIUserNotificationSettings *mySettings =
                [UIUserNotificationSettings settingsForTypes:types categories:nil];
    
    [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
    
    0 讨论(0)
提交回复
热议问题