iOS - 关于极光推送的步骤

来源:互联网 发布:小说语音阅读软件 编辑:程序博客网 时间:2024/05/18 21:41

其实简书上关于极光推送的文章已经很多,并且也很详细,所以,此篇文章仅作为自己日后的一个参考,仅此一点存在价值。so,本文讲述一下配置极光推送的步骤:

1.先说证书的事情:

developer.apple.com---->identifiers--->>  选择APP IDS.  创建一个app id , 填写需要推送的项目的 bundle id,创建完成之后,开启推送服务,创建推送证书,(有两个),创建完推送证书之后,要导出到桌面的 p12, 导出的时候要分清哪个是开发的,哪个是发布的,关于导出时候,不能展开证书的情况我不知道真假,反正不展开就好。然后把两个p12上传到极光推送的官网应用上。

2.这两个地方开启



3.导入必要的依赖库,如图:



4.把极光的文件夹(Lib)拖入工程,最好 add files to...,如下图所示:



Appdelegate.h 中:

// 极光推送的配置信息

static NSString *appKey =@"";//申请应用成功以后官方会提供给你


static NSString *channel =@"";


static BOOL isProduction =FALSE;


在Appdelegate.m中导入头文件#import “JPUSHService.h”


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

   

    // 极光推送

    //Required

    if ([[UIDevicecurrentDevice].systemVersionfloatValue] >= 10.0) {

#ifdef NSFoundationVersionNumber_iOS_9_x_Max

        JPUSHRegisterEntity * entity = [[JPUSHRegisterEntityalloc] init];

        entity.types =UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;

        [JPUSHServiceregisterForRemoteNotificationConfig:entitydelegate:nil];

#endif

    } elseif ([[UIDevicecurrentDevice].systemVersionfloatValue] >= 8.0) {

        //可以添加自定义categories

        [JPUSHServiceregisterForRemoteNotificationTypes:(UIUserNotificationTypeBadge |

                                                          UIUserNotificationTypeSound |

                                                          UIUserNotificationTypeAlert)

                                              categories:nil];

    } else {

        //categories 必须为nil

        [JPUSHServiceregisterForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert)categories:nil];

    }




    returnYES;

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

    [UIApplicationsharedApplication].applicationIconBadgeNumber =0;

}


#pragma mark - 极光推送的配置方法----------

// 极光推送的配置方法

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    

    NSLog(@"获得了token值为::::%@",deviceToken);

    

    // Required

    

    [JPUSHServiceregisterDeviceToken:deviceToken];

    

}




- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    

    

    

    // Required,For systems with less than or equal to iOS6

    

    [JPUSHServicehandleRemoteNotification:userInfo];

    

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    

    

    

    // IOS 7 Support Required

    

    [JPUSHServicehandleRemoteNotification:userInfo];

    

    completionHandler(UIBackgroundFetchResultNewData);

    

}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

    

    

    

    //Optional

    

    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);

    

}


写到这里,极光推送的配置就好了。。。
0 0
原创粉丝点击