http://docs.jpush.cn/pages/viewpage.action?pageId=2621727
1、在apple开发者平台创建 “Apple Push Services”,不赘述
2、下载cer证书后,在钥匙串导出p12证书,输入密码
3、在iOS的app管理界面,上传p12证书,输入密码,点击上传。验证成功
4、xcode增加jpush-ios-2.1.0.a、JPUSHService.h
5、修改应用的 Capabilities 开启Remote notifications
6、AppDelegate.m 增加代码
static NSString *appKey = @"********************";
static NSString *channel = @"developer-default";
static BOOL isProduction = TRUE;
// Override point for customization after application launch.
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];
}
[JPUSHService setupWithOption:launchOptions appKey:appKey
channel:channel apsForProduction:isProduction];
//Resign textField if touched outside of UITextField/UITextView.
[[IQKeyboardManager sharedManager] setShouldResignOnTouchOutside:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//将所有返回的json中的id映射成item_id
[JSONModel setGlobalKeyMapper:[[JSONKeyMapper alloc] initWithDictionary:@{@"id":@"item_id"}]];
});
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (userInfo) {
// 取得 APNs 标准信息内容
NSDictionary *aps = [userInfo valueForKey:@"aps"];
NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容
// badge = [[aps valueForKey:@"badge"] integerValue]; //badge数量
NSString *sound = [aps valueForKey:@"sound"]; //播放的声音
// 取得自定义字段内容
NSString *customizeField1 = [userInfo valueForKey:@"key"]; //自定义参数,key是自己定义的
NSLog(@"content =[%@], badge=[%ld], sound=[%@], customize field =[%@]",content,badge,sound,customizeField1);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:content
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定", nil];
[alert show];
// Required
[JPUSHService handleRemoteNotification:userInfo];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[JPUSHService setBadge:0];
}
}