java中的接口是类吗
409
2022-10-31
点击app系统消息打开app并进入指定页面
NSDictionary* message = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
通过上面的代码可以获取到字典。 服务器按照第4个透传消息模版推送的消息,其中自定义字段,键是payload,值时对应的一个json字符串。客户端收到的消息,打印日志如下(我们的推送在推送模块AWGeTuiModule里不是在AppDelegate文件里,所以你看到日志文件名是AWGeTuiModule.m):
2018/09/11 17:29:02:329 AWGeTuiModule.m:AWGeTuiModule.m:-[AWGeTuiModule application:didFinishLaunchingWithOptions:]:37 Verbose:didFinishLaunchingWithOptions2018/09/11 17:29:02:344 AWGeTuiModule.m:AWGeTuiModule.m:-[AWGeTuiModule application:didFinishLaunchingWithOptions:]:45 Verbose:didFinishLaunchingWithOptions message:{ "_ge_" = 1; "_gmid_" = "OSS-0911_59e9037e052e7333e399614830e701a7:d910d849e38349e8ab2e7278520d8bcb:2c2ea418e66ec33e367fc1a24223fb65"; "_gurl_" = "sdk.open.extension.getui.com:8123"; aps = { alert = { body = test; title = "\U60a8\U6709\U4e00\U6761\U672a\U8bfb\U6d88\U606f"; }; badge = 2; "content-available" = 1; "mutable-content" = 1; sound = default; }; payload = "{\"title\":\"\U60a8\U6709\U4e00\U6761\U672a\U8bfb\U6d88\U606f\",\"body\":\"test\",\"redirectUrl\":\"className]:__NSDictionaryI2018/09/11 17:29:02:345 AWGeTuiModule.m:AWGeTuiModule.m:-[AWGeTuiModule application:didFinishLaunchingWithOptions:]:49 Verbose:payload:{"title":"您有一条未读消息","body":"test","redirectUrl":"className]:__NSCFString2018/09/11 17:29:02:345 AWGeTuiModule.m:AWGeTuiModule.m:-[AWGeTuiModule application:didFinishLaunchingWithOptions:]:53 Verbose:jsondata:<7b227469 746c6522 3a22e682 a8e69c89 e4b880e6 9da1e69c aae8afbb e6b688e6 81af222c 22626f64 79223a22 74657374 222c2272 65646972 65637455 726c223a 22687474 70733a2f 2f6d2e31 2d6a6f79 2e636f6d 2f6d6172 6b65742f 67696674 2f616765 6e742f6d 616e6167 652e6874 6d3f6361 7449643d 31343533 33227d>,[jsondata className]:NSConcreteMutableData2018/09/11 17:29:02:345 AWGeTuiModule.m:AWGeTuiModule.m:-[AWGeTuiModule application:didFinishLaunchingWithOptions:]:57 Verbose:jsonObject:{ body = test; redirectUrl = " title = "\U60a8\U6709\U4e00\U6761\U672a\U8bfb\U6d88\U606f";},[jsonObject className]:__NSDictionaryI,[jsonObject isKindOfClass:[NSDictionary class]]:1, error:(null)2018/09/11 17:29:02:346 AWGeTuiModule.m:AWGeTuiModule.m:-[AWGeTuiModule application:didFinishLaunchingWithOptions:]:61 Verbose:redirectUrl:className]:__NSCFString
可以看到payload对应的是一个Json串,进行解析后,redirectUrl的地址就是登录后所要强制跳转的页面参数。
个推测试网站的测试消息这样填写。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ FLDDLogVerbose(@"didFinishLaunchingWithOptions"); // [EXT] 重新上线 [GeTuiSdk startSdkWithAppId:kGeXinAppId appKey:kGeXinAppKey appSecret:kGeXinAppSecret delegate:self]; // 注册 APNs [self registerRemoteNotification]; // [2-EXT]: 获取启动时收到的APN NSDictionary* message = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; FLDDLogVerbose(@"didFinishLaunchingWithOptions message:%@,[message className]:%@", message, [message className]); if (message) {// [AWSingleObject sharedInstance].redirectUrl = @" NSString *payload = [message objectForKey:@"payload"]; FLDDLogVerbose(@"payload:%@,[payload className]:%@", payload, [payload className]); if(payload) { self.payloadFlag = YES; NSData* jsondata = [payload dataUsingEncoding:NSUTF8StringEncoding]; FLDDLogVerbose(@"jsondata:%@,[jsondata className]:%@", jsondata, [jsondata className]); NSError *error = nil; id jsonObject = [NSJSONSerialization JSONObjectWithData:jsondata options:NSJSONReadingAllowFragments error:&error]; FLDDLogVerbose(@"jsonObject:%@,[jsonObject className]:%@,[jsonObject isKindOfClass:[NSDictionary class]]:%d, error:%@", jsonObject ,[jsonObject className], [jsonObject isKindOfClass:[NSDictionary class]], error); if(!error && jsonObject && [jsonObject isKindOfClass:[NSDictionary class]]) { NSString *redirectUrl = [jsonObject safeObjectForKey:@"redirectUrl"]; FLDDLogVerbose(@"redirectUrl:%@,[redirectUrl className]:%@", redirectUrl, [redirectUrl className]); if(redirectUrl) { [AWSingleObject sharedInstance].redirectUrl = redirectUrl;// [[NSNotificationCenter defaultCenter] postNotificationName:@"redirectLoginNotification" object:nil userInfo:@{@"redirectUrl":@" } } }// NSString *record = [NSString stringWithFormat:@"[APN]%@, %@", [NSDate date], payload]; //如何跳转页面自己添加代码 // // self.window.rootViewController = self.viewController; } self.isLaunch = YES; return YES;}
我们的处理是,调整模块的加载顺序(由modules.plist里的各个成员的顺序决定),保证组件管理模块首先启动,其次加载框架与日志模块,然后加载个推模块, 加载框架类组件(AWUISkeleton,根目录或tabbar),最后加载登录模块。把个推模块获取的到redirectUrl存入单例对象的变量(单例的生成是可以忽略时间的)中。在设置根页面(登录页面)时,把单例变量赋值给登录页面的成员变量。在AWLoginViewController的viewDidLoad中通过 self.loginView.redirectUrl = _redirectUrl;设置变量,AWLoginView类中重置-(void)setRedirectUrl:(NSString *)redirectUrl函数。通过self.loginPanel.redirectUrl = self.redirectUrl;设置变量,AWLoginPanel类中重置-(void)setRedirectUrl:(NSString *)redirectUrl函数,并调用登录按钮函数。那为何AWLoginViewController不重置-(void)setRedirectUrl:(NSString *)redirectUrl函数呢?因为通常AWLoginViewController在创建成功,并不是立即加载页面控件,而是在回调viewDidLoad函数时加载页面控件,这个函数回调是有时间差的,而-(void)setRedirectUrl:(NSString *)redirectUrl是立即生效的,无时间差的。调用AWLoginView *loginView = [[AWLoginView alloc]init];那么AWLoginView的初始化函数init立即执行,立即创建了页面控件,所以可以用采用重置-(void)setRedirectUrl:(NSString *)redirectUrl函数来实现跳转参数的传递与处理。相关部分代码如下:
AWUISkeleton.m文件
#import "AWLoginViewController.h"@interface AWUISkeleton ()@end@implementation AWUISkeleton+ (AWUISkeleton *)sharedInstance{ static AWUISkeleton *instance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ instance = [[AWUISkeleton alloc] init]; }); return instance;}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ FLDDLogVerbose(@"didFinishLaunchingWithOptions");// self.tabBarController = [[UXTabBarController alloc] initWithViewControllers:@[[[AWHomeTitlesViewController alloc] init], [[AWArtClassificationViewController alloc] init], [[AWFindViewController alloc] init], [[AWMineViewController alloc] init]]];// self.tabBarController.uxTabBarControllerDelegate = self; AWLoginViewController *loginViewController = [[AWLoginViewController alloc] init]; if(!isEmptyString([AWSingleObject sharedInstance].redirectUrl)) { loginViewController.redirectUrl = [AWSingleObject sharedInstance].redirectUrl; } YXNavigationController *navigationController = [[YXNavigationController alloc] initWithRootViewController:loginViewController]; navigationController.navigationBar.hidden = YES; navigationController.navigationBarHidden = YES; if ([UIApplication sharedApplication].delegate.window == nil) { [UIApplication sharedApplication].delegate.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; [UIApplication sharedApplication].delegate.window.backgroundColor = [UIColor blackColor]; } [UIApplication sharedApplication].delegate.window.rootViewController = navigationController; [[UIApplication sharedApplication].delegate.window makeKeyAndVisible]; [[NSNotificationCenter defaultCenter] postNotificationName:skeletonDidFinishLaunchNotification object:self userInfo:launchOptions]; return YES;}@end
AWLoginViewController.m文件
- (void)viewDidLoad { [super viewDidLoad]; AWLoginView *loginView = [[AWLoginView alloc]init]; [self.view addSubview:loginView];#if AGENT_APP loginView.frame = CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight);#else loginView.frame = CGRectMake(0, kMainStatusBarHeight, kUIScreenWidth, kUIScreenHeight - kMainStatusBarHeight);#endif self.loginView = loginView; self.loginView.redirectUrl = _redirectUrl; FLDDLogVerbose(@"redirectUrl:%@", _redirectUrl);}
AWLoginView.m文件
-(void)setRedirectUrl:(NSString *)redirectUrl{ _redirectUrl = redirectUrl; if(!isEmptyString(self.redirectUrl)) { self.loginPanel.isRedirectLoginFlag = YES; } self.loginPanel.redirectUrl = self.redirectUrl; FLDDLogVerbose(@"redirectUrl:%@", self.loginPanel.redirectUrl);}
AWLoginPanel.m文件
下面是页面跳转时的部分日志:
2018/09/11 17:29:02:346 AWGeTuiModule.m:AWGeTuiModule.m:-[AWGeTuiModule application:didFinishLaunchingWithOptions:]:61 Verbose:redirectUrl:className]:__NSCFString2018/09/11 17:29:02:346 AWUISkeleton.m:AWUISkeleton.m:-[AWUISkeleton application:didFinishLaunchingWithOptions:]:39 Verbose:didFinishLaunchingWithOptions2018/09/11 17:29:02:616 AWLoginViewController.m:AWLoginViewController.m:-[AWLoginViewController viewDidLoad]:36 Verbose:page2018/09/11 17:29:02:640 AWLoginPane.m:AWLoginPanel.m:-[AWLoginPanel setRedirectUrl:]:179 Verbose:redirectUrl:self.isRedirectLoginFlag:12018/09/11 17:29:02:640 AWLoginPane.m:AWLoginPanel.m:-[AWLoginPanel login:]:317 Verbose:self.isRedirectLoginFlag:1, self.redirectUrl:17:29:02:717 AWLoginView.m:AWLoginView.m:-[AWLoginView setRedirectUrl:]:194 Verbose:redirectUrl:17:29:02:717 AWLoginViewController.m:AWLoginViewController.m:-[AWLoginViewController viewDidLoad]:48 Verbose:redirectUrl:17:29:03:181 AWBizModule.m:AWBizModule.m:-[AWBizModule monitoringNetworkStatus]_block_invoke:187 Verbose:status:22018/09/11 17:29:03:181 AWBizModule.m:AWBizModule.m:-[AWBizModule monitoringNetworkStatus]_block_invoke:189 Verbose:networkStatus:22018/09/11 17:29:03:288 AWGeTuiModule.m:AWGeTuiModule.m:-[AWGeTuiModule GeTuiSDkDidNotifySdkState:]:281 Debug:aStatus:02018/09/11 17:29:03:294 AWGeTuiModule.m:AWGeTuiModule.m:-[AWGeTuiModule application:didRegisterForRemoteNotificationsWithDeviceToken:]:131 Debug:>>>[DeviceToken Success]:2d8f670a8a3213768b98c9685713bf7f4900829fec3d977a3303d2fbdc638046 kGeXinAppId:pQBQPh84rgAEnXRP9xR4Q42018/09/11 17:29:03:295 AWGeTuiModule.m:AWGeTuiModule.m:-[AWGeTuiModule application:didRegisterForRemoteNotificationsWithDeviceToken:]:141 Debug:函数 clientId:2c2ea418e66ec33e367fc1a24223fb652018/09/11 17:29:03:974 AWUpdateVersionModel.m:AWUpdateVersionModel.m:-[AWUpdateVersionModel setupRACCommand]_block_invoke_3:91 Verbose:data:{ appCode = agent; appId = 4; appName = "\U827a\U4eab\U4f18\U9009"; remark = ""; type = ios; update = N; version = "1.0.0";}2018/09/11 17:29:03:975 AWBizModule.m:AWBizModule.m:-[AWBizModule forceUpdte]_block_invoke:361 Verbose:resultUpdateVersionEntity:
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
评论列表