我的应用程序处于未运行状态我点击通知其打开的主页,但我想打开特定页面,但它的工作当应用程序在前台和后台时,但我在app代理的一种方法中编写了这段代码警报视图显示所有状态。
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler
{
NSDictionary *userInfo = response.notification.request.content.userInfo;
NSDictionary *dict = userInfo[kAps];
NSString *str = [NSString stringWithFormat:@"%@",[dict valueForKey:kAlert]];
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
MyOrderDetailVC *view = [[UIStoryboard storyboardWithName:kMainStoryboard bundle:nil] instantiateViewControllerWithIdentifier:@"MyOrderDetailVC"];
NSString *orderstatus = userInfo[kgcmnotificationorderstatus];
NSString *ordertype = userInfo[kgcmnotificationordertype];
view.isFromSideMenu = YES;
view.isfromViewOrders = YES;
view.status = orderstatus; //[NSString stringWithFormat:@"%@",[dictOrderDetails valueForKey:korderstatus]];
view.isProduct =ordertype;
view.strOrderStatus = orderstatus;
view.strProgramId = @"-1";
if([ordertype isEqualToString: @"0"])
{
view.isBookedOrders = NO;
}
if([ordertype isEqualToString: @"1"])
{
view.isBookedOrders =YES;
}
if([orderstatus isEqualToString:@"0"])
{
view.strOrderStatus = kPending;
}
else if([orderstatus isEqualToString:@"1"])
{
view.strOrderStatus = kConfirmed;
}
else if ([orderstatus isEqualToString:@"2"])
{
view.strOrderStatus = kCompleted;
}
[navController.visibleViewController.navigationController pushViewController:view animated:YES];
[[Shared sharedInstance] showAlertViewInViewController:kAppName message:str buttonTitles:@[OK] viewC:self.window.rootViewController handler:nil];
}
答案 0 :(得分:0)
当您的应用未运行且您希望在Notification
方法中检测到didFinishLaunchingWithOptions
,如下所示
-(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (localNotif) {
// Notification detect here
// Put your code here so it will be call when your App will not running state and tapped on Notification.
}
}
答案 1 :(得分:0)
在didFinishLaunchingWithOptions中,检查通知是或注意
NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification)
{
NSLog(@"app recieved notification %@",notification);
// open your particular controller
}else{
NSLog(@"app did not recieve notification");
}