1.进入https://www.jpush.cn/common/products,注册用户,下载ADK,查看使用说明
2.简单的在AppDelegate中添加如下代码
#import "AppDelegate.h"
#import "APService.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//2ef3e25980d0a77068b83b89
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert)
categories:nil];
//launchOptions 远程通知的内容
[APService setupWithOption:launchOptions];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
//设置用户的别名 账号 而且每个人不一样
[APService setAlias:@"137" callbackSelector:nil object:nil];
//上传DeviceToken
[APService registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required
[APService handleRemoteNotification:userInfo];
}
//后台 真后台
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// IOS 7 Support Required
//[APService handleRemoteNotification:userInfo];
//代码块
//后台 还在继续运行 (下载 加载图片信息 -> 耗时 : 30)
completionHandler(UIBackgroundFetchResultNewData);
}