在我的ios项目中集成Box IOS sdk

时间:2014-03-20 10:46:10

标签: ios iphone objective-c ipad ios7

我试图在我的ios项目中集成BOX V2 IOS SDk,集成很好,但是当我尝试登录时,在我输入用户名和密码并授予访问权限后,我得到一个白屏,并且没有调用boxAPIAuthenticationDidSucceed方法,她是我的代码 联系方式:

-(void) connectToBox {
  [BoxSDK sharedSDK].OAuth2Session.clientID = @"my-client-id";
  [BoxSDK sharedSDK].OAuth2Session.clientSecret = @"my-client-secret";

  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(boxAPIAuthenticationDidSucceed:)
                                               name:BoxOAuth2SessionDidBecomeAuthenticatedNotification
                                             object:[BoxSDK sharedSDK].OAuth2Session];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(boxAPIAuthenticationDidFail:)
                                             name:BoxOAuth2SessionDidReceiveAuthenticationErrorNotification
                                           object:[BoxSDK sharedSDK].OAuth2Session];


self.LoginCotroller = [[BoxAuthorizationViewController alloc] initWithAuthorizationURL:authorizationURL redirectURI:redirectURI];

[self presentViewController:self.LoginCotroller animated:YES completion:nil];

}

我实现了两种方法:

- (void)boxAPIAuthenticationDidSucceed:(NSNotification *)notification;
- (void)boxAPIAuthenticationDidFail:(NSNotification *)notification;

和通知方法:

#pragma mark - Handle OAuth2 session notifications
- (void)boxAPIAuthenticationDidSucceed:(NSNotification *)notification
{
 BoxOAuth2Session *session = (BoxOAuth2Session *) notification.object;
 NSLog(@"Received OAuth2 successfully authenticated notification");
 NSLog(@"Access token  (%@) expires at %@", session.accessToken,  session.accessTokenExpiration);
  NSLog(@"Refresh token (%@)", session.refreshToken);

  dispatch_sync(dispatch_get_main_queue(), ^{
    [self.LoginCotroller dismissViewControllerAnimated:YES completion:nil];
});
}

- (void)boxAPIAuthenticationDidFail:(NSNotification *)notification
{
   NSLog(@"Received OAuth2 failed authenticated notification");
   NSString *oauth2Error = [[notification userInfo]     valueForKey:BoxOAuth2AuthenticationErrorKey];
   NSLog(@"Authentication error  (%@)", oauth2Error);

   dispatch_sync(dispatch_get_main_queue(), ^{
       [self dismissViewControllerAnimated:YES completion:nil];
   });
}

我不知道我的代码有什么问题。如果有人可以提供帮助。谢谢

1 个答案:

答案 0 :(得分:0)

我建议将控制器添加为BoxOAuth2SessionDidRefreshTokensNotification的观察者,并调用boxAPIAuthenticationDidSucceed:方法。 BoxOAuth2SessionDidRefreshTokensNotification在创建/刷新新访问令牌时发布。