1

当我在调试模式下在 iPhone 模拟器中进行身份验证时,if运行下面代码中的第一条语句。但是,当我在安装了 Evernote 客户端的 iPhone 上进行调试时,该if语句不会出现评估。取而代之的是,Evernote iOS 应用程序会出现片刻,然后直接返回到此 ViewController,而不会在 if 下设置任何断点,也不会触发 segue。

有任何想法吗?

[session authenticateWithViewController:self completionHandler:^(NSError *error) {
    if (error || !session.isAuthenticated){
        if (error) {
            NSLog(@"Error authenticating with Evernote Cloud API: %@", error);
        }
        if (!session.isAuthenticated) {
            NSLog(@"Session not authenticated");
        }
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                        message:@"Could not authenticate"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    } else {
        // We're authenticated!
        EvernoteUserStore *userStore = [EvernoteUserStore userStore];
        [userStore getUserWithSuccess:^(EDAMUser *user) {
            // success
            NSLog(@"Authenticated as %@", [user username]);

            [self performSegueWithIdentifier:@"introductionStepOne" sender:self];
        } failure:^(NSError *error) {
            // failure
            NSLog(@"Error getting user: %@", error);
        } ];
    }
}];
4

1 回答 1

1

确保正确修改 AppDelegate。更多信息在这里:https ://github.com/evernote/evernote-sdk-ios#modify-your-appdelegate

您需要添加:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:      (NSString *)sourceApplication annotation:(id)annotation {
BOOL canHandle = NO;
    if ([[NSString stringWithFormat:@"en-%@", [[EvernoteSession sharedSession] consumerKey]]     isEqualToString:[url scheme]] == YES) {
    canHandle = [[EvernoteSession sharedSession] canHandleOpenURL:url];
    }
    return canHandle;
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was     inactive. If the application was previously in the background, optionally refresh the user     interface.
    [[EvernoteSession sharedSession] handleDidBecomeActive];
}
于 2013-03-26T01:01:15.440 回答