0

我想做这样的功能:

当我的应用程序的通知被触发时,如下图所示:

在此处输入图像描述

我向右滑动栏中的应用程序图标,应用程序应该运行并显示特定视图。

但我不知道该怎么做。

在我的应用程序中:(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;
}

但是在我向右滑动图标后,我的应用程序根本没有运行。

任何人都可以帮忙吗?

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

4

1 回答 1

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);
  ...
}
于 2013-07-11T13:46:12.667 回答