Search code examples
swiftpush-notificationibm-cloud

Swift 2 : Push notification settings


Im having some problems with the push notification code form Bluemix that can be found here.

https://console.ng.bluemix.net/docs/services/mobilepush/t_enable_ios_notifications_register.html

********* Dont know how i missed that this question already excisted *******

The code i have written that gives me an error is:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let notificationTypes: UIUserNotificationType = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound
    let notificationSettings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
    application.registerUserNotificationSettings(notificationSettings)
    application.registerForRemoteNotifications()

    return true

}

The error its gives me is: "No '|' candidates produce the expected contexual result type 'UIUserNotificationType'. To clear its the second "|" that is wrong.


This question i havent found on Stackoverflow though:

Later in my code(Appdelegate) i get an error in this code:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

And it says: "Invalid redeclartion of 'application(_:didRecieiveRemoteNotification:fetchCompletionHander:)"

Any ideas what that even means?


Solution

  • Its an array in swift

    let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Sound, UIUserNotificationType.Alert, UIUserNotificationType.Badge]