iOS 集成极光推送 (swift版)

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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值