注册于iOS的迅速通知7(Registering for iOS 7 notifications i

2019-10-21 19:50发布

我希望能有在iOS 7和iOS 8通知,我已经建立了其与iOS8上的成功,但这个iOS的7我得到的上线只是“LLDB”没有别的错误“变种mySettings ......”。 从我读过这是什么,你是如何打算注册它在iOS 7,但似乎并没有工作!

   func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> bool{

    //check if its on ios8

    var deviceVersion :  NSString = UIDevice.currentDevice().systemVersion



    if deviceVersion.floatValue >= 8.0 {

     //I've set up the iOS 8 notifications here and that all works.

    }else{



        var types : UIUserNotificationType = UIUserNotificationType.Badge | UIUserNotificationType.Alert;



        var mySettings : UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)



        UIApplication.sharedApplication().registerUserNotificationSettings(mySettings)



    }





    return true

}

Answer 1:

你的问题是:

UIApplication.sharedApplication()。registerUserNotificationSettings(mySettings)

这不是在IOS支持7.你应该实现这样的事情:

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
{
   //do ios7 stuff here. If you are using just local notifications then you dont need to do anything. for remote notifications:
application.registerForRemoteNotificationTypes(UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge)
}
return true
}


文章来源: Registering for iOS 7 notifications in swift