iOS 极光推送

本文详细介绍了如何在iOS应用中集成极光推送服务,包括下载证书、配置项目、导入SDK、设置代理文件等内容,确保应用能够接收并处理推送通知。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用极光推送需要去AppleDevelope中下载证书
这里写图片描述

其中极光推送需要的证书是.p12证书,齿轮状的证书数手机证书

下载完证书需要配置项目工程
首先需要导入从官方下载的SDK中的lib文件夹中的文件
这里写图片描述
然后再去加载需要的框架
这里写图片描述
还需要添加一个.plist文件
这里写图片描述
其中APP_KEY是极光推送的key

上面设置完,又在极光网站注册完那就需要在AppleDelegate.h代理文件中填写内容了

#import "AppDelegate.h"
#import "JPUSHService.h"
#import "RootController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    RootController *root = [[RootController alloc]init];
    self.window.rootViewController = root;
    [self.window makeKeyAndVisible];

    // Required
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        //可以添加自定义categories
        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                          UIUserNotificationTypeSound |
                                                          UIUserNotificationTypeAlert)
                                              categories:nil];
    } else {
        //categories 必须为nil
        [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                          UIRemoteNotificationTypeSound |
                                                          UIRemoteNotificationTypeAlert)
                                              categories:nil];
    }

    // Required
    //如需兼容旧版本的方式,请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化和同时使用pushConfig.plist文件声明appKey等配置内容。
    // [JPUSHService setupWithOption:launchOptions];
    [JPUSHService setupWithOption:launchOptions appKey:appKey channel:channel apsForProduction:isProduction];
    return YES;
}

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

    // Required
    [JPUSHService registerDeviceToken:deviceToken];
}

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

    // Required,For systems with less than or equal to iOS6
    [JPUSHService handleRemoteNotification:userInfo];
}

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

    // IOS 7 Support Required
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}

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

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

@end

还需要结合极光官方文档———— 最重要的还是证书

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值