Swift 2.2 集成lean cloud Push推送

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

        // 注册一个通知 通知换控制器 “新特性”
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(switchRootViewController), name: SwitchRootViewControllerKey, object: nil)
        
        // 注册 Cloud
        setCloud(launchOptions)

        //创建window
        window = windowNew()
 
        //注册 通知APNs
        registerForPushNotifications(application)
        
        return true
    }

    //注册 通知APNs
    func registerForPushNotifications(application: UIApplication) {
        let notificationSettings = UIUserNotificationSettings(
            forTypes: [.Badge, .Sound, .Alert], categories: nil)
        application.registerUserNotificationSettings(notificationSettings)
    }
   
    
    //注册远程推送通知了
    func application(application: UIApplication,didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
        if notificationSettings.types != .None {
            application.registerForRemoteNotifications()
        }
    }
    ///deviceToken推送服务器
    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        AVOSCloud.handleRemoteNotificationsWithDeviceToken(deviceToken)
    }
    //失败
    func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
        print(error)
    }
    

你可能感兴趣的:(Swift 2.2 集成lean cloud Push推送)