Ios 当应用程序通过通知触发时,如何显示特定视图?
我想做这样的功能: 当我的应用程序的通知被触发时,如下图所示: 我在右边的栏中滑动应用程序图标,应用程序应该运行并显示特定视图 但我不知道怎么做 在我的应用程序中:Ios 当应用程序通过通知触发时,如何显示特定视图?,ios,Ios,我想做这样的功能: 当我的应用程序的通知被触发时,如下图所示: 我在右边的栏中滑动应用程序图标,应用程序应该运行并显示特定视图 但我不知道怎么做 在我的应用程序中:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项,我写道: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
,我写道:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSString *objectIDURL = [localNotif.userInfo objectForKey:@"objectIDURI"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
EventViewController *eventViewController = [storyboard instantiateViewControllerWithIdentifier:@"EventViewController"];
[eventViewController setEvent:[Event getEventByObjectIDURL:objectIDURL]];
[(UINavigationController*)self.window.rootViewController pushViewController:eventViewController animated:NO];
}
return YES;
}
但在我向右滑动图标后,我的应用程序根本无法运行
有人能帮忙吗
另外,我正在使用故事板,我不知道它是否相关。您从未说过这是本地通知还是远程通知,但消息传递对这两者的作用几乎相同。您必须记住,如果应用程序正在运行或未运行,系统会以不同的方式通知您。也就是说,如果你双击home(主页)按钮并在底部看到应用程序的图标,那么它就是“正在运行”(我的术语) 您需要做的是确保实现了所有相关的委托方法,并且请记录其中的每一个方法,以便您可以在测试时验证发送的消息。从UIApplication.h复制并粘贴它们,这样您就不会出现拼写错误(也就是说,拼写错误,因为系统不会对这些错误给出警告!) 实施以下所有措施:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// if launched due to a notification, you will get a non-nil launchOptions
NSLog(@"didFinishLaunchingWithOptions: launchOptions=%@", launchOptions);
...
}
// if using remote notifications
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Better get this for remote notifications
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken: token=%@", deviceToken);
...
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"YIKES! didFailToRegisterForRemoteNotificationsWithError");
...
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// if already running, notification came in
NSLog(@"didReceiveRemoteNotification: userInfo=%@", userInfo);
...
}
// if using local notifications
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
// if already running, notification came in
NSLog(@"didReceiveLocalNotification: notification=%@", notification);
...
}
if条件通过验证了吗?
application:didReceivereMotentification:
@rakeshNS,我不清楚你的问题是什么意思。?如果(localNotif)是真的还是假的?@rakeshNS,这是一个指针,如果(localNotif)应该是真的,当应用程序通过通知启动时,我想谢谢你!我正在使用本地通知,现在我想知道如何使用NSLog进行调试?例如,如果我想使用选项测试DidFinishLaunching,我必须先关闭iPhone中的应用程序,然后XCode将抛出一个信号SIGKILL,我再也看不到NSLog。日志消息将输出到设备控制台日志-您可以在XCode Organizer窗口中看到它们-转到设备,打开设备,然后查看日志。