简体   繁体   中英

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 :

-(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 is posted when a new access-token is created/refresed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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