本文主要是介绍信鸽推送_使用自定义参数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.看这篇文章前应当已经实现了简单的推送功能,如果没有实现,可以看这篇文字:http://developer.xg.qq.com/index.php/Main_Page
2.这篇文章主要解决的问题是如何使用信鸽【自定义参数】跳转页面,在信鸽推送设置页面有这样的功能:
程序分为两种状态:
1.程序从后台被退出、程序在后台:这种情况下,接受到通知后,点击通知,会调用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
在这个方法中可以这样来解析自定义参数:
NSDictionary * userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSString *valueString = [userInfo objectForKey:@"myKey"];
解析完后可以根据你解析的结果进行跳转:
UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];if ([valueString isEqualToString:@"myValue"]) {self.cyLVC =[secondStroyBoard instantiateViewControllerWithIdentifier:@"SecondViewController"];}else{self.cyLVC =[secondStroyBoard instantiateViewControllerWithIdentifier:@"ViewController"];}self.myVC = [[UINavigationController alloc]initWithRootViewController:self.cyLVC];CGRect rect=[[UIScreen mainScreen] bounds];self.window=[[UIWindow alloc]initWithFrame:rect];self.window.rootViewController=self.myVC;[self.window makeKeyAndVisible];return YES;
2.程序在前台,你正在使用程序,那么会调用这个方法:
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
在这个方法中,你可以直接根据userInfo来获取值:
NSString *valueString = [userInfo objectForKey:@"myKey"];
然后进行相应的跳转操作。
这篇关于信鸽推送_使用自定义参数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!