极光推送swift

//  
//  AppDelegate.swift  
//  swift3.0-jiguang  
//  
//  Created by xxx on 2018/01/02.  
//  Copyright © 2018年 xxx. All rights reserved.  
//  
  
import UIKit  
  
@UIApplicationMain  
class AppDelegate: UIResponder, UIApplicationDelegate {  
  
    var window: UIWindow?  
  
  
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {  
        if #available(iOS 10.0, *){  
            let entiity = JPUSHRegisterEntity()  
            entiity.types = Int(UNAuthorizationOptions.alert.rawValue |  
                                UNAuthorizationOptions.badge.rawValue |  
                                UNAuthorizationOptions.sound.rawValue)  
            JPUSHService.register(forRemoteNotificationConfig: entiity, delegate: self)  
        } else if #available(iOS 8.0, *) {  
            let types = UIUserNotificationType.badge.rawValue |  
                        UIUserNotificationType.sound.rawValue |  
                        UIUserNotificationType.alert.rawValue  
            JPUSHService.register(forRemoteNotificationTypes: types, categories: nil)  
        }else {  
            let type = UIRemoteNotificationType.badge.rawValue |  
                       UIRemoteNotificationType.sound.rawValue |  
                       UIRemoteNotificationType.alert.rawValue  
            JPUSHService.register(forRemoteNotificationTypes: type, categories: nil)  
        }  
          
        JPUSHService.setup(withOption: launchOptions,  
                           appKey: "4adfb75ea2e6b055ccb04891",  
                           channel: "app store",  
                           apsForProduction: false)  
        return true  
    }  
  
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {  
        JPUSHService.registerDeviceToken(deviceToken)  
    }  
      
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {  
        JPUSHService.handleRemoteNotification(userInfo)  
        completionHandler(.newData)  
          
    }  
      
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {  
        JPUSHService.handleRemoteNotification(userInfo)  
    }  
  
}  
  
extension AppDelegate : JPUSHRegisterDelegate{  
    func jpushNotificationCenter(_ center: UNUserNotificationCenter!, willPresent notification: UNNotification!, withCompletionHandler completionHandler: ((Int) -> Void)!) {  
        print(">JPUSHRegisterDelegate jpushNotificationCenter willPresent");  
        let userInfo = notification.request.content.userInfo  
        if (notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))!{  
            JPUSHService.handleRemoteNotification(userInfo)  
        }  
        completionHandler(Int(UNAuthorizationOptions.alert.rawValue))// 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置  
    }  
      
    func jpushNotificationCenter(_ center: UNUserNotificationCenter!, didReceive response: UNNotificationResponse!, withCompletionHandler completionHandler: (() -> Void)!) {  
        print(">JPUSHRegisterDelegate jpushNotificationCenter didReceive");  
        let userInfo = response.notification.request.content.userInfo  
        if (response.notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))!{  
            JPUSHService.handleRemoteNotification(userInfo)  
        }  
        completionHandler()  
    }  
}  
/* 
 */  

你可能感兴趣的:(极光推送swift)