原文地址:iphone之push作者:飞舞的鸡毛
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
在客户端注册 push 开启 标记 提醒 声音
有两个委托的方法
//获取本机的deviceToken
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
//get the valid devicetoken, then send to our server
NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"Token: %@", token);
}
//注册失败时
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
//failed to get token, do something...
NSLog(@"%@", error);
}
//接收push消息的时候
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
if (userInfo) {
pushDict = [userInfo retain];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unicom OA" message:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看",nil];
[alert show];
[alert release];
}
}
现在做的项目服务器端的push是不能到达手机端的,应该是两边的证书问题。。。。
取消push
//取消注册
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
留言列表