- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//注册推送通知
// [[UIApplication sharedApplication]registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
//
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:(UIUserNotificationTypeSound |
UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge)
categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else {
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|
UIRemoteNotificationTypeBadge|
UIRemoteNotificationTypeSound];
}
if (launchOptions) {
// UIApplicationLaunchOptionsRemoteNotificationKey 这个key值就是push的信息
NSDictionary *dic = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
// 为了复用代码,统一到下面这个处理方法中handlePushNotify:
[self handlePushNotify:dic fromBuld:_ISPushFromClosed]; //如果程序没有启动,点击推送消息进入程序,需要根据推送消息做一些处理,如:视图切换等。
}
//注册远程推送,成功后的代理方法
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
//苹果服务器返回的token (苹果服务器用来标识手机的唯一编号)
//可以交给后台,然后后台需要给此发送远程推送的时候直接用这个token
NSString *tokenStr = [deviceToken description];
NSLog(@"token:%@",tokenStr);
}
//注册远程推送失败
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"注册推送失败%@",error);
}
//程序正在运行时,点击推送消息所走的方法
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//在这里可以根据推送信息做一些操作
[self handlePushNotify:userInfo fromBuld:_ISPushFromOpen];
}
-(void)handlePushNotify:(NSDictionary *)dic fromBuld:(NSString *)buld
{
// 根据buld判断是哪里传来的值
/*
dic = {
aps = {
alert = "\U627e\U5927\U592b\U63d0\U793a\Uff1ahdf21\U7528\U6237\U7533\U8bf7\U52a0\U5165\U60a8\U7684\U5c0f\U680b\U5708\U5708\U5b50";
sound = default;
target = {
"param_list" = (
{
"param_name" = "circle_id";
"param_value" = 2204;
},
{
"param_name" = "circle_name";
"param_value" = "\U5c0f\U680b\U5708";
},
{
"param_name" = type;
"param_value" = 1;
}
);
topage = "/gooddoc/server/index.php/circle/getCircleMembersNews";
};
};
*/
}