iOS YouTube 身份验证 EXC_BAD_EXCEPTION

iOS YouTube authentication EXC_BAD_EXCEPTION

我运行这段代码here,它运行良好。 但是,我在尝试将其添加到我的项目时遇到了问题。 class YouTubeHelper 调用后 showAuthenticationViewController:

– (void)showAuthenticationViewController:(UIViewController *)authView {
    [self.navigationController presentViewController:authView animated:NO completion:nil];
}

Inside GTMOAuth2ViewControllerTouch.m 我得到一个 exc_bad_access,inside loadView,在 [super loadView],如下:

– (void)loadView {
    NSString *nibPath = nil;
    NSBundle *nibBundle = [self nibBundle];
    if (nibBundle == nil) {
        nibBundle = [NSBundle mainBundle];
    }
    NSString *nibName = self.nibName;
    if (nibName != nil) {
        nibPath = [nibBundle pathForResource:nibName ofType:@”nib”];
    }
    if (nibPath != nil && [[NSFileManager defaultManager] fileExistsAtPath:nibPath]) {
        [super loadView]; <<<< exc_bad_access here!
    } else {
        // One of the requirements of loadView is that a valid view object is set to
        // self.view upon completion. Otherwise, subclasses that attempt to
        // access self.view after calling [super loadView] will enter an infinite
        // loop due to the fact that UIViewController's -view accessor calls
        // loadView when self.view is nil.
        self.view = [[[UIView alloc] init] autorelease];

#if DEBUG
        NSLog(@"missing %@.nib", nibName);
#endif
    }
}

知道为什么会发生这种情况以及如何解决它吗?

谢谢!

你不应该在你的子类中调用 [super loadView];。从您的实施中删除该行。

You can override this method in order to create your views manually. If you choose to do so, assign the root view of your view hierarchy to the view property. The views you create should be unique instances and should not be shared with any other view controller object. Your custom implementation of this method should not call super.

参考:UIViewController Class Reference

感谢 Midhun 和 EridB。

由于库有点旧,我自己实现了将视频上传到 YouTube。

这里有一些对它有帮助的链接:

https://developers.google.com/youtube/v3/guides/implementation/videos

https://developers.google.com/youtube/v3/guides/using_resumable_upload_protocol

特别是这个非常有用,可以尝试检查 request/response:

https://developers.google.com/oauthplayground/?code=4/1c_ILMzPMhgPWpCI6L7M-LeBe5jL-BY1Xa1sS0oWQJ0

我希望它能帮助其他人实施 YouTube API。