2013-07-11 41 views
0

我想做出这样的功能:如何通过通知触发应用程序时显示某些视图?

当我的应用程序的通知解雇,像下面的图片:

enter image description here

我刷在酒吧右侧的应用图标,应用程序应运行并显示一定的视图。

但我不知道该怎么做。

在我的应用程序:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions,我写:

- (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; 
} 

但我刷卡右边的图标后,我的应用程序并不运行在所有。

任何人都可以帮忙吗?

另外,我正在使用故事板,我不知道它是否相关。

+0

if条件是否通过验证? – rakeshNS

+0

'应用程序:didReceiveRemoteNotification:' – Desdenova

+0

@rakeshNS,我不清楚你的问题是什么意思。? – HanXu

回答

0

你从来没有说过,如果这是一个本地或远程通知,但消息对两者的工作几乎相同。您必须记住,如果应用程序正在运行,或者未运行,系统会以不同的方式通知您。也就是说,如果你双击主页按钮并在底部看到应用程序的图标,那么它的“运行”(我的术语)。

你需要做的是确保你已经实现了所有相关的委托方法,并且请NSLog每一个都这样,这样你就可以在你测试的时候验证哪些消息正在被消息传递。复制并从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); 
    ... 
} 
+0

谢谢!我使用本地通知,我现在想知道如何使用NSLog进行调试?例如,如果我想测试didFinishLaunchingWithOptions,我必须先关闭iPhone中的应用程序,然后XCode会发出一个SIGKILL信号,我不能再看到NSLog。 – HanXu

+0

将日志消息输出到设备控制台日志 - 您可以在Xcode Organizer窗口中看到它们 - 进入设备,打开设备,然后查看日志。 –

+0

明白了,谢谢! – HanXu

相关问题