Swift3.0 信鸽推送


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


        // 注册

        XGSetting .getInstance()

        XGPush.startApp(ACCESS_ID, appKey: ACCESS_KEY)

        XGPush.isPush { (Bool) in

        //print("[XGDemo] Push Is %@", isPush)

        }

        XGPush.handleLaunching(launchOptions!, successCallback: {

            print("success")

        }) { 

            print("error")

                }


        return true

    }

    func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {


    }


    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {


        let deviceTokenStr = XGPush.registerDevice(deviceToken as Data, successCallback: { () -> Void in

            print("[XGPush]register successBlock\n\n")

            }) { () -> Void in

                print("[XGPush]register errorBlock\n\n")

        }

        

        print("deviceTokenStr:\(deviceTokenStr)\n\n")

    }

    

    

    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {

        print("didFailToRegisterForRemoteNotifications error:\(error.localizedDescription)\n\n")

    }


    /**

     收到通知的回调


     @param application  UIApplication 实例

     @param userInfo 推送时指定的参数

     */


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

    {

        print("[XGDemo] userinfo %@", userInfo)

        //消息在userinfo["aps"]

        //弹窗

        // 清空通知栏通知

        UIApplication.shared.cancelAllLocalNotifications()

        UIApplication.shared.applicationIconBadgeNumber = 0


    }

    /**

     收到静默推送的回调


     @param application  UIApplication 实例

     @param userInfo 推送时指定的参数

     @param completionHandler 完成回调

     */

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

        print("[XGDemo] receive slient Notification")

        print("[XGDemo] userinfo %@", userInfo)

        XGPush.handleReceiveNotification(userInfo, successCallback: { 

            print("[XGDemo] Handle receive success")

        }) { 

            print("[XGDemo] Handle receive error")

        }

        completionHandler(UIBackgroundFetchResult.newData)

    }



你可能感兴趣的:(Swift)