极光推送 idfa官网idfa是什么意思

iOS基础(58)
苹果在iOS10上对apns推送做了修改, 极光也是很给力的, 在第一时间就对sdk进行了更新, 下面对iOS10注册极光推送进行一下记录.
首先, 在极光的开发者服务里注册应用获取appKey, 在apple Developer配置推送证书...等等等这些废话就不说了.
兼容iOS10的是极光2.1.9版本的sdk.
1. 导入SDK
2. 导入SDK依赖的框架
CFNetwork.framework
CoreFoundation.framework
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
Foundation.framework
UIKit.framework
Security.framework
Xcode7需要的是libz.Xcode7以下版本是libz.dylib
Adsupport.framework (获取IDFA需要;如果不使用IDFA,请不要添加)
UserNotifications.framework(Xcode8及以上)
3. 设置Build Setting中, Search Paths的User Header Search Paths
&4.如果用的是Xcode8及以上环境开发需要开启Application Target的Capabilities-&Push Notifications选项这两个一定要都是对号 , 这个选项不开启在iOS10后不会注册成功
添加这个选项会在项目中多这样一个文件
5. 不要忘记Xcode7以上需要支持http传输方式
下面是需要写的代码部分:
6. 在AppDelegate.m中, 引入头文件
// 极光推送
#import &JPUSHService.h&
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
// 这里是iOS10需要用到的框架
7. 设置注册极光推送需要的一些参数
static NSString * const JPUSHAPPKEY = @&xxxxxxxxxxxxxxxxx&; // 极光appKey
static NSString * const channel = @&Publish channel&; // 固定的
#ifdef DEBUG // 开发
static BOOL const isProduction = FALSE; // 极光FALSE为开发环境
#else // 生产
static BOOL const isProduction = TRUE; // 极光TRUE为生产环境
8. 这里是AppDelegate.m中的代码, 分了几大块, 全部粘到下面, 直接复制可用(只需要下面这些代码就可以实现通知)
AppDelegate.m
iOS10_JPUSH
Created by 周昊 on 16/9/18.
Copyright (C) 2016年 周昊. All rights reserved.
#import &AppDelegate.h&
// 极光推送
#import &JPUSHService.h&
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
// 这里是iOS10需要用到的框架
static NSString * const JPUSHAPPKEY = @&xxxxxxxxxxxxxxxxx&; // 极光appKey
static NSString * const channel = @&Publish channel&; // 固定的
#ifdef DEBUG // 开发
static BOOL const isProduction = FALSE; // 极光FALSE为开发环境
#else // 生产
static BOOL const isProduction = TRUE; // 极光TRUE为生产环境
@interface AppDelegate () // 最新版的sdk需要实现这个代理方法
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 注册apns通知
if ([[UIDevice currentDevice].systemVersion floatValue] &= 10.0) // iOS10
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge | UNAuthorizationOptionS
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
else if ([[UIDevice currentDevice].systemVersion floatValue] &= 8.0) // iOS8, iOS9
//可以添加自定义categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
else // iOS7
//categories 必须为nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil];
launchingOption 启动参数.
appKey 一个JPush 应用必须的,唯一的标识.
channel 发布渠道. 可选.
isProduction 是否生产环境. 如果为开发状态,设置为 NO; 如果为生产状态,应改为 YES.
advertisingIdentifier 广告标识符(IDFA) 如果不需要使用IDFA,传nil.
* 此接口必须在 App 启动时调用, 否则 JPush SDK 将无法正常工作.
// 广告标识符
NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
// 如不需要使用IDFA,advertisingIdentifier 可为nil
// 注册极光推送
[JPUSHService setupWithOption:launchOptions appKey:JPUSHAPPKEY channel:channel apsForProduction:isProduction advertisingIdentifier:advertisingId];
//2.1.9版本新增获取registration id block接口。
[JPUSHService registrationompletionHandler:^(int resCode, NSString *registrationID) {
if(resCode == 0)
// iOS10获取registrationID放到这里了, 可以存到缓存里, 用来标识用户单独发送推送
NSLog(@&registrationID获取成功:%@&,registrationID);
[[NSUserDefaults standardUserDefaults] setObject:registrationID forKey:@&registrationID&];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@&registrationID获取失败,code:%d&,resCode);
return YES;
// ---------------------------------------------------------------------------------
- (void)applicationWillResignActive:(UIApplication *)application {
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
- (void)applicationWillEnterForeground:(UIApplication *)application {
[application setApplicationIconBadgeNumber:0];
[application cancelAllLocalNotifications];
- (void)applicationDidBecomeActive:(UIApplication *)application {
- (void)applicationWillTerminate:(UIApplication *)application {
// ---------------------------------------------------------------------------------
#pragma mark - 注册推送回调获取 DeviceToken
#pragma mark -- 成功
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
// 注册成功
// 极光: Required - 注册 DeviceToken
[JPUSHService registerDeviceToken:deviceToken];
#pragma mark -- 失败
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
// 注册失败
NSLog(@&did Fail To Register For Remote Notifications With Error: %@&, error);
// ---------------------------------------------------------------------------------
// 这部分是官方demo里面给的, 也没实现什么功能, 放着以备不时之需
#if __IPHONE_OS_VERSION_MAX_ALLOWED & __IPHONE_7_1
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
// Called when your app has been activated by the user selecting an action from
// a local notification.
// A nil action identifier indicates the default action.
// You should call the completion handler as soon as you've finished handling
// the action.
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
// Called when your app has been activated by the user selecting an action from
// a remote notification.
// A nil action identifier indicates the default action.
// You should call the completion handler as soon as you've finished handling
// the action.
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
// ---------------------------------------------------------------------------------
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
[JPUSHService showLocalNotificationAtFront:notification identifierKey:nil];
// ---------------------------------------------------------------------------------
#pragma mark - iOS7: 收到推送消息调用
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// iOS7之后调用这个
[JPUSHService handleRemoteNotification:userInfo];
NSLog(@&iOS7及以上系统,收到通知&);
if ([[UIDevice currentDevice].systemVersion floatValue] & 10.0 || application.applicationState & 0)
// 程序在前台或通过点击推送进来的会弹这个alert
NSString *message = [NSString stringWithFormat:@&iOS7-8-9收到的推送%@&, [userInfo[@&aps&] objectForKey:@&alert&]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@&提示& message:message delegate:self cancelButtonTitle:@&确定& otherButtonTitles:nil, nil];
[alert show];
completionHandler(UIBackgroundFetchResultNewData);
// ---------------------------------------------------------------------------------
#pragma mark - iOS10: 收到推送消息调用(iOS10是通过Delegate实现的回调)
#pragma mark- JPUSHRegisterDelegate
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
// 当程序在前台时, 收到推送弹出的通知
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
NSDictionary * userInfo = notification.request.content.userI
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]])
[JPUSHService handleRemoteNotification:userInfo];
NSString *message = [NSString stringWithFormat:@&will%@&, [userInfo[@&aps&] objectForKey:@&alert&]];
NSLog(@&iOS10程序在前台时收到的推送: %@&, message);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@&提示& message:message delegate:self cancelButtonTitle:@&确定& otherButtonTitles:nil, nil];
[alert show];
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以设置
// 程序关闭后, 通过点击推送弹出的通知
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
NSDictionary * userInfo = response.notification.request.content.userI
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]])
[JPUSHService handleRemoteNotification:userInfo];
NSString *message = [NSString stringWithFormat:@&did%@&, [userInfo[@&aps&] objectForKey:@&alert&]];
NSLog(@&iOS10程序关闭后通过点击推送进入程序弹出的通知: %@&, message);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@&提示& message:message delegate:self cancelButtonTitle:@&确定& otherButtonTitles:nil, nil];
[alert show];
completionHandler();
// 系统要求执行这个方法
注: 极光的AppKey要自己到极光的官网申请哦
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:38587次
积分:1175
积分:1175
排名:千里之外
原创:76篇
转载:27篇
评论:11条
(1)(16)(1)(1)(43)(22)(16)(4)当前位置:
& Swift - JPush极光推送的使用1(配置、简单的推送测试样例)
Swift - JPush极光推送的使用1(配置、简单的推送测试样例)
发布:hangge
阅读:1431
一,APNs介绍
(1)APNs 是 Apple Push Notification service 的简称,中文翻译为:苹果推送通知服务。
(2)APNs 允许设备与苹果的推送通知服务器保持常连接状态。当你想发送一个推送通知给某个用户的iPhone上的应用程序时,你可以使用 APNs 发送一个推送消息给目标设备上已安装的某个应用程序。
(3)APNs 也是 iOS 系统里唯一的推送方式。 
二,&极光推送(JPush)介绍
(1)极光推送是一个端到端的推送服务,使得服务器端消息能够及时地推送到终端用户手机上。
(2)推送客户端支持 Android, iOS 两个平台。(iOS下使用APNs推送)
(3)为 JPush Server 上报 Device Token,免除开发者管理 Device Token 的麻烦。
(4)前台运行时,可接收由 JPush 下发的(透传的)自定义消息。
(5)灵活管理接收用户:Tag(标签分组)、Alias(用户别名)、RegistrationID(设备注册ID)
三,使用极光推送的优点
虽然我们可以搭建自己应用服务器,将需要被推送的信息发给APNs。接着由APNs推送到指定的iOS设备上,然后再由设备通知到我们的应用程序,最后设备以通知或者声音的形式通知用户有新的消息。
但使用 JPush SDK 可以更快捷地为 iOS App 增加推送功能,减少集成 APNs 需要的工作量、开发复杂度,也让服务器端向 iOS 设备推送变得更加简单方便。
四,极光推送SDK集成步骤
1、在JPush Portal上创建应用
在 JPush 的管理 Portal 上创建应用并上传 APNs 证书。如果对 APNs 证书不太了解 请参考:
创建成功后自动生成 AppKey 用以标识该应用。
2,导入API开发包到应用程序项目
将 iOS SDK 包解压。下载地址:
然后把解压后的 lib 子文件夹(包含 JPUSHService.h、jpush-ios-x.x.x.a)添加到你的工程目录中。
3,创建并配置个桥接头文件将JPUSHService.h引入进来
#import "JPUSHService.h"
4,添加必要的框架
(1)CFNetwork.framework
(2)CoreFoundation.framework
(3)CoreTelephony.framework
(4)SystemConfiguration.framework
(5)CoreGraphics.framework
(6)Foundation.framework
(7)UIKit.framework
(8)Security.framework
(9)libz.tbd
(10)Adsupport.framework (获取 IDFA 需要;如果不使用 IDFA,请不要添加)
(11)libresolv.tbd(JPush 2.2.0及以上版本需要)
5,允许XCode7支持Http传输方法
如果用的是 Xcode7&或者更新的版本时,需要在App项目 info.plist 中添加如下配置以支持 http 传输。
&key&NSAppTransportSecurity&/key&
&key&NSAllowsArbitraryLoads&/key&
6,开启Remote notifications
需要在 Xcode 中修改应用的 Capabilities 开启 Remote notifications
7,开启Push Notifications
如使用 Xcode8 及以上环境开发,还要开启 Capabilities 下的 Push Notifications 选项。
8,最后在AppDelegate.swift中添加如下代码,启动JPush的SDK服务。
(本文代码已升级至 Swift3)
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -& Bool {
//通知类型(这里将声音、消息、提醒角标都给加上)
let userSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound],
categories: nil)
if ((UIDevice.current.systemVersion as NSString).floatValue &= 8.0) {
//可以添加自定义categories
JPUSHService.register(forRemoteNotificationTypes: userSettings.types.rawValue,
categories: nil)
//categories 必须为nil
JPUSHService.register(forRemoteNotificationTypes: userSettings.types.rawValue,
categories: nil)
// 启动JPushSDK
JPUSHService.setup(withOption: nil, appKey: "7becfd",
channel: "Publish Channel", apsForProduction: false)
return true
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//注册 DeviceToken
JPUSHService.registerDeviceToken(deviceToken)
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler
completionHandler: @escaping (UIBackgroundFetchResult) -& Void) {
//增加IOS 7的支持
JPUSHService.handleRemoteNotification(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
func application(_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
NSLog("did Fail To Register For Remote Notifications With Error: \(error)")
//..........
JPUSHService.setupWithOption()方法的参数说明:
指明应用程序包的下载渠道,为方便分渠道统计,具体值由你自行定义,如:App Store。
填写管理Portal上创建应用后自动生成的AppKey值。请确保应用内配置的 AppKey 与第1步在 Portal 上创建应用后生成的 AppKey 一致。
apsForProduction
1.3.1版本新增,用于标识当前应用所使用的APNs证书环境。
0 (默认值)表示采用的是开发证书,1 表示采用生产证书发布应用。
注:此字段的值要与Build Settings的Code Signing配置的证书环境一致。
五,推送测试
1,我们将上面配置好的应用编译发布到手机上(使用模拟器无法测试 JPush 推送)
2,第一次运行程序会提示我们是否允许推送通知,选择“好”即可。
控制台输出消息如下:
3,将程序退出。接着我们到极光推送网站上的控制台模块来进行消息发送的测试。
在“推送”-&“发送通知”页面中,输入需要推送的消息及相关配置(这里我们选择广播,即给所有人都发生推送)。点击“立即发送”。
4,通知发送后,虽然我们的应用之前已经关闭了,但我们可以看到手机上还是会成功显示接收到的通知消息。iOS开发总结(51)
iOS推送实际是个很辛苦的过程,不过大部分工作苹果已经做过了,我们所要做的就是传设备号即Device Token之类的,现在记录下一些第一次做推送时候遇到的困惑
1:&&& 极光推送可以有很多方式,比如全推,比如根据tag推,比如别名推,但是大致原理大同小异,极光需要我们上传我们当前设备的Device Token,然后根据这个东西让苹果的APNS来找到这个设备进行推送,如果我们做全推的话就不用其他的了,只需要把Device Token传给极光,服务端推送的时候,会推送到所有安装的设备,若是定向推送的话,就要一个唯一的东西跟你的Device Token 绑定,然后服务端需要知道这个东西,然后他们根据这个东西推给极光,极光根据这个东西查询出对应的Token
Device 然后给苹果,苹果来推送。
2:&& 集成第三方文档的时候要注意,是要上传两份P12文件的,一份开发,一份上线用的,上线用的证书上传后就不用管了,主要是测试证书,证书做好后要跟新下新的配置文件,这样才能拿到token值证书申请这里就不在叙述,都是固定的流程。
3:&&& 定点推送时候的绑定,Device Token需要绑定register_id或者tag值或者别名,其中 register_id是极光帮我们生成的,我们需要用函数获取,其他的是我们自己向极光注册的,最好用唯一标识符进行注册,比如设备的UUID 或IDFA之类的,极光会将这个东西与Device Token 进行绑定,然后服务端获取这个东西,推送的时候根据这个识别是那个用户
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:21450次
排名:千里之外
原创:60篇
(6)(1)(4)(4)(4)(8)(3)(1)(3)(2)(3)(2)(4)(2)(1)(10)(4)

我要回帖

更多关于 极光推送官网登录 的文章

 

随机推荐