iOS 极光推送在接到消息后跳到,想要的某一页实现办法
2016-12-08 10:05
316 查看
1.
#pragma mark
极光推送在收到消息后,执行的方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Required, iOS 7 Support
获取到的数据
[JPUSHService
handleRemoteNotification:userInfo];
_pushDic = [[NSMutableDictionary
alloc]init];
NSDictionary *dic= userInfo [@"aps"];
[_pushDic
setValue:[userInfo
objectForKey:@"_j_msgid"]
forKey:@"_j_msgid"];
[_pushDic
setValue:userInfo [@"order_number"]
forKey:@"order_number"];
[_pushDic
setValue:dic[@"alert"]
forKey:@"alert"];
[_pushDic
setValue:dic[@"badge"]
forKey:@"badge"];
[_pushDic
setValue:dic[@"sound"]
forKey:@"sound"];
completionHandler(UIBackgroundFetchResultNewData);
if ([UIApplication
sharedApplication].applicationState ==
UIApplicationStateActive) {//这是在前台
[self
creatOrderAlertView];
}else{//这是在后台
[self
goToMssageViewControllerWith:_pushDic];
}
}
2.
#pragma mark
在前台接到消息后执行的办法
-(void)creatOrderAlertView{
UIAlertView * alert = [[UIAlertView
alloc]
initWithTitle:@"推送消息"
message:@"您有一条新的推送消息!"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"查看",nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[JPUSHService
resetBadge];
if (buttonIndex==1) {
[self
goToMssageViewControllerWith:_pushDic];
}
}
3.
#pragma mark 》》》》》》》》》》》》》》》极光推送后台跳转方法《《《《《《《《《《《《《《《《《《《《《《《《《《《《
- (void)goToMssageViewControllerWith:(NSDictionary*)msgDic{
//将字段存入本地,因为要在你要跳转的页面用它来判断,这里我只介绍跳转一个页面,
NSUserDefaults*pushJudge = [NSUserDefaults standardUserDefaults];
[pushJudge setObject:@"push"forKey:@"push"];
[pushJudge synchronize];
NSString * targetStr = [msgDic objectForKey:@"_j_msgid"];
if (targetStr) {
MyOrderViewController * VC = [[MyOrderViewController alloc]init];
UINavigationController * Nav = [[UINavigationController alloc]initWithRootViewController:VC];//这里加导航栏是因为我跳转的页面带导航栏,如果跳转的页面不带导航,那这句话请省去。
[[self topViewController] presentViewController:Nav animated:YES completion:nil];
}
}
4.
#pragma mark 通过我下面的函数可以获取当前的controller
- (UIViewController*)topViewController{
return [self
topViewControllerWithRootViewController:self.window.rootViewController];
}
- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController{
if ([rootViewController
isKindOfClass:[UITabBarController
class]]) {
UITabBarController *tabBarController = (UITabBarController *)rootViewController;
return [self
topViewControllerWithRootViewController:tabBarController.selectedViewController];
} else
if ([rootViewController
isKindOfClass:[UINavigationController
class]]) {
UINavigationController* navigationController = (UINavigationController*)rootViewController;
return [self
topViewControllerWithRootViewController:navigationController.visibleViewController];
} else
if (rootViewController.presentedViewController) {
UIViewController* presentedViewController = rootViewController.presentedViewController;
return [self
topViewControllerWithRootViewController:presentedViewController];
} else {
return rootViewController;
}
}
#pragma mark
极光推送在收到消息后,执行的方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Required, iOS 7 Support
获取到的数据
[JPUSHService
handleRemoteNotification:userInfo];
_pushDic = [[NSMutableDictionary
alloc]init];
NSDictionary *dic= userInfo [@"aps"];
[_pushDic
setValue:[userInfo
objectForKey:@"_j_msgid"]
forKey:@"_j_msgid"];
[_pushDic
setValue:userInfo [@"order_number"]
forKey:@"order_number"];
[_pushDic
setValue:dic[@"alert"]
forKey:@"alert"];
[_pushDic
setValue:dic[@"badge"]
forKey:@"badge"];
[_pushDic
setValue:dic[@"sound"]
forKey:@"sound"];
completionHandler(UIBackgroundFetchResultNewData);
if ([UIApplication
sharedApplication].applicationState ==
UIApplicationStateActive) {//这是在前台
[self
creatOrderAlertView];
}else{//这是在后台
[self
goToMssageViewControllerWith:_pushDic];
}
}
2.
#pragma mark
在前台接到消息后执行的办法
-(void)creatOrderAlertView{
UIAlertView * alert = [[UIAlertView
alloc]
initWithTitle:@"推送消息"
message:@"您有一条新的推送消息!"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"查看",nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[JPUSHService
resetBadge];
if (buttonIndex==1) {
[self
goToMssageViewControllerWith:_pushDic];
}
}
3.
#pragma mark 》》》》》》》》》》》》》》》极光推送后台跳转方法《《《《《《《《《《《《《《《《《《《《《《《《《《《《
- (void)goToMssageViewControllerWith:(NSDictionary*)msgDic{
//将字段存入本地,因为要在你要跳转的页面用它来判断,这里我只介绍跳转一个页面,
NSUserDefaults*pushJudge = [NSUserDefaults standardUserDefaults];
[pushJudge setObject:@"push"forKey:@"push"];
[pushJudge synchronize];
NSString * targetStr = [msgDic objectForKey:@"_j_msgid"];
if (targetStr) {
MyOrderViewController * VC = [[MyOrderViewController alloc]init];
UINavigationController * Nav = [[UINavigationController alloc]initWithRootViewController:VC];//这里加导航栏是因为我跳转的页面带导航栏,如果跳转的页面不带导航,那这句话请省去。
[[self topViewController] presentViewController:Nav animated:YES completion:nil];
}
}
4.
#pragma mark 通过我下面的函数可以获取当前的controller
- (UIViewController*)topViewController{
return [self
topViewControllerWithRootViewController:self.window.rootViewController];
}
- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController{
if ([rootViewController
isKindOfClass:[UITabBarController
class]]) {
UITabBarController *tabBarController = (UITabBarController *)rootViewController;
return [self
topViewControllerWithRootViewController:tabBarController.selectedViewController];
} else
if ([rootViewController
isKindOfClass:[UINavigationController
class]]) {
UINavigationController* navigationController = (UINavigationController*)rootViewController;
return [self
topViewControllerWithRootViewController:navigationController.visibleViewController];
} else
if (rootViewController.presentedViewController) {
UIViewController* presentedViewController = rootViewController.presentedViewController;
return [self
topViewControllerWithRootViewController:presentedViewController];
} else {
return rootViewController;
}
}
相关文章推荐
- iOS 服务器返回NSData数据,解析为null
- ios循环请求数据的正确方法
- 苹果开发者证书
- iOS开发--iOS 指纹识别常见问题汇总
- 关于ios8版本录音跳转时上方闪红条跳转后self.view上移问题
- ios 创建圆形布局
- iOS开发中常用的宏定义
- iOS应用之间的跳转
- iOS 极光推送消息推送成功,但是手机收不到的解决方法。
- iOS 持续集成系列 - 自动化 Code Review
- ios %.2f是四舍五入吗?你真的了解ios四舍五入的规则吗?
- iOS 持续集成
- iOS 第三方登陆 —— 新浪微博
- iOS截取图片的一部分
- iOS相机相册使用权限
- iOS 单例模式
- Git 【git merge】
- 新MacBook Pro再出问题:频繁关机/死机_广州达内IOS培训
- iPhone 6s电池故障出厂时间范围矿大_广州达内IOS培训
- 苹果回应自燃事件:系外力导致_广州达内IOS培训