简体   繁体   English

将Box IOS SDK集成到我的ios项目中

[英]Integrate Box IOS sdk in my ios project

I'm trying to integrate BOX V2 IOS SDk on my ios project , the integration is fine, but when I try to login , and after I enter my username and password and granted the access , I get a white screen , and the boxAPIAuthenticationDidSucceed method is not called , her is my code the connexion Method : 我正在尝试将BOX V2 IOS SDk集成到我的ios项目中,这种集成很好,但是当我尝试登录时,在输入用户名和密码并授予访问权限后,出现白屏,并且显示了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];

}

and I implement the two methods : 并且我实现了两种方法:

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

and the notifications methods : 以及通知方法:

#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];
   });
}

I dont know what wrong with my code.So if any one can help.Thanks 我不知道我的代码有什么问题,所以任何人都可以帮忙。

I'd suggest adding your controller as an observer for BoxOAuth2SessionDidRefreshTokensNotification as well to call boxAPIAuthenticationDidSucceed: method. 我建议将您的控制器添加为BoxOAuth2SessionDidRefreshTokensNotification的观察者,并调用boxAPIAuthenticationDidSucceed:方法。 BoxOAuth2SessionDidRefreshTokensNotification is posted when a new access-token is created/refresed. 创建/刷新新的访问令牌时,将发布BoxOAuth2SessionDidRefreshTokensNotification。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM