//
// 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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...