我想做这样的功能:
触发我的应用通知时,如下图所示:
我向右滑动栏中的应用图标,应该运行该应用并显示某个视图。
但我不知道该怎么做。
在我的申请中:(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 :(得分: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);
...
}