先配置好百度开发文档中的东西,一下实现一个在回调中获取连接,跳转。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
self.userInfo = userInfo;
NSString *alert = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
//页面激活的状态下 (不在后台)
if (application.applicationState == UIApplicationStateActive) {
//有链接的时候 就是资讯 @“urls”这个是自己服务器添加的字段
if(nil!=[userInfo objectForKey:@"urls"])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"资讯新闻"
message:alert
delegate:self
cancelButtonTitle:@"稍后"
otherButtonTitles:@"立即查看",nil];
[alertView show];
}else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"新消息"
message:alert
delegate:self
cancelButtonTitle:@"我知道了"
otherButtonTitles:nil];
[alertView show];
}
}
//在后台的时候
else
{
if(nil!=[userInfo objectForKey:@"urls"])
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"url" object:nil userInfo:userInfo];
}
}
[application setApplicationIconBadgeNumber:0];
[BPush handleNotification:userInfo];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==1)
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"url" object:nil userInfo:self.userInfo];
}
}
在VC中
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openAction:) name:@"url" object:nil];
-(void)openAction:(NSNotification *)notify
{
//跳转的指定页面
}