美文网首页
极光推送swift

极光推送swift

作者: 浩瀚海洋里的木头 | 来源:发表于2018-01-02 11:41 被阅读51次
//  
//  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

  • 极光推送(Swift)

    1、使用cocoapod集成 2、注册APNs 3、向苹果发送deviceToken 4、实现极光代理方法 可以在...

  • Swift3.0对接极光JPushNotificationExt

    极光推送之前有提到过,如有问题可以看:极光推送 极光一直在升级,我们也需要一直学习,今天Swift对接一下极光3....

  • SWIFT集成极光JPUSH推送

    今天记录一下用swift集成极光推送 一、首先到极光推送的官网下载iOS对应的SDK包 SDK下载地址,地址自己...

  • swift 集成极光推送

    在极光官网下申请程序。 进行证书配置,证书分开发证书,跟生产证书。用xcode跑到手机上的项目需要开发证书,打包上...

  • Swift 之 极光推送----

    小菜鸟正在爬坑过程中,有问题欢迎讨论指教~~~~之前做推送用的是百度推送,这是第一次用极光,看完极光的文档发现 其...

  • Swift_极光推送

    iOS 平台上推送通知,只有 APNs 这个官方的通道,是可以随时送达的。一般开发者都是自己部署应用服务器向 AP...

  • 极光推送

    极光推送视频地址,非常详细的极光推送视频 极光推送

  • Swift3.0 极光推送

    前提 本文目的是方便以后自己查看,还请各位朋友高抬贵手、不喜勿喷,谢谢??? 一、极光推送通知 1.当app处于后...

  • Swift中配置极光推送

    因为要适配iOS 10以下的系统,所以在配置极光推送时要做一些处理。先上代码,等会儿慢慢说,或者有问题可以在下面留...

网友评论

      本文标题:极光推送swift

      本文链接:https://www.haomeiwen.com/subject/ceyfnxtx.html