0

从本地通知加载我的应用程序时,我正在尝试读取其有效负载。为此,我有以下代码:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Loading Stuff

    UILocalNotification *localNotif =
    [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotif) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
        [(UITabBarController *)self.window.rootViewController setSelectedIndex:1];
        UINavigationController *nav = [[(UITabBarController *)self.window.rootViewController viewControllers] objectAtIndex:1];
        IMTRewardsViewController *rvc = [storyboard instantiateViewControllerWithIdentifier:@"rewardsView"];
        [rvc loadPushNotification:localNotif];
        [nav pushViewController:rvc animated:NO];

    }

    return YES;
}

IMTRewardsController.h:

-(NSDictionary *)loadPushNotification:(UILocalNotification *)notification;

IMTRewardsController.m:

- (NSDictionary *)loadPushNotification:(UILocalNotification *)notification
{
    NSLog(@"%@",notification.userInfo);
    return notification.userInfo;
}

当我从本地通知加载我的应用程序时,我收到以下错误:

<Error>: -[UIViewController loadPushNotification]: unrecognized selector sent to instance 0x14e70b30
<Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController loadPushNotification]: unrecognized selector sent to instance 0x14e70b30'

关于如何解决这个问题并防止它在未来出现的任何想法?

4

2 回答 2

2

有错误表明您拉回的视图控制器只是一个 UIViewController,而不是您期望的 IMTRewardsViewController。您确定在情节提要中将自定义类属性设置为该类型吗?

于 2013-10-07T21:47:32.797 回答
0

您可能需要先投射它。故事板返回一个 UIViewController

IMTRewardsViewController *rvc = (IMTRewardsViewController *)[storyboard instantiateViewControllerWithIdentifier:@"rewardsView"];
于 2013-10-07T21:49:49.680 回答