原文地址:iphone之push作者:飞舞的鸡毛

push原理:
http://www.cocoachina.com/newbie/basic/2010/0401/900.html
 
服务器端的代码是用c#定的。引用的官方的例子。代码在联通项目中。
 
客户端代码如下:

 

[[UIApplication sharedApplicationregisterForRemoteNotificationTypes:

 UIRemoteNotificationTypeBadge |

 UIRemoteNotificationTypeAlert |

 UIRemoteNotificationTypeSound];

 

在客户端注册 push 开启 标记 提醒 声音

 

有两个委托的方法

 

//获取本机的deviceToken

 

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

//get the valid devicetoken, then send to our server

NSString *token = [[deviceToken descriptionstringByTrimmingCharactersInSet:[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 allocinitWithTitle:@"Unicom OA" message:[[userInfo objectForKey:@"aps"objectForKey:@"alert"delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看",nil];

[alert show];

[alert release];

}

}

 

 

 

现在做的项目服务器端的push是不能到达手机端的,应该是两边的证书问题。。。。

 

 

取消push

 

    //取消注册
    [[UIApplication sharedApplication] unregisterForRemoteNotifications];

 

arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()