iOS 集成极光推送 (swift版)
1、使用cocoapods安装极光推送SDK
之前项目使用的是信鸽推送,但是后面不知怎么地,就是收不到推送消息了,安卓,iOS都是,然后就换成了极光;
我用的是cocoapods安装,也可以在官网下载SDK拖拽进你的工程里
cocoapods安装及使用[https://www.jianshu.com/p/265d8e4dd73a]
在Podfile添加JPush
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target '******' do
pod 'JPush' #极光推送
use_frameworks!
end
然后在终端进入你的项目目录,执行 pod install
2、注册及配置极光推送相关
在Header.h引入相关文件
#ifndef Header_h
#define Header_h
/*极光推送*/
#import "JPUSHService.h"
// iOS10注册APNs所需头文件
//#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#import <UserNotifications/UserNotifications.h>
#endif
#endif /* Header_h */
AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate,JPUSHRegisterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//注册极光推送
registerJPush()
return true
}
func registerJPush(){
//注册极光推送
let entity = JPUSHRegisterEntity()
entity.types = 1 << 0 | 1 << 1 | 1 << 2
JPUSHService.register(forRemoteNotificationConfig: entity, delegate: self)
//需要IDFA 功能,定向投放广告功能
//let advertisingId = ASIdentifierManager.shared().advertisingIdentif