迅速注册iOS 7通知

问题描述:

我希望能够在iOS 7和iOS 8上发布通知,我已经成功地使用ios8进行了设置,但是此iOS 7中出现“lldb”错误行“var mySettings ...”。从我读过的这个是你如何在iOS 7注册它,但它似乎并没有工作!迅速注册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 

} 

您的问题是:

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 
}