2014-06-20 5 views
0

Dropbox 설명서는 기본적으로 인증에 대한 응답이 Appdelegate.m에 발생 함을 설명합니다. 내 자신의 클래스의 대리인을 동일한 방식으로 수행하는 방법은 무엇입니까? 정보 PLIST의 URL 유형에서Dropbox 인증 응답 처리

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url 
    sourceApplication:(NSString *)source annotation:(id)annotation { 
    if ([[DBSession sharedSession] handleOpenURL:url]) { 
     if ([[DBSession sharedSession] isLinked]) { 
      NSLog(@"App linked successfully!"); 
      // At this point you can start making API calls 
     } 
     return YES; 
    } 
    // Add whatever other url handling code your app requires here 
    return NO; 
} 
+0

나는 당신이이 생각하지 않는다 'openURL'이 구현 된 곳에 대한 선택. 나는 당신의'UIApplication' 클래스 (보통'AppDelegate.m'라는 파일)의 멤버 여야한다고 믿습니다. – smarx

답변

0

enter image description here -> URL 체계에서는이 메소드가 호출되는 것이다 DB-YourAppKey를 추가합니다.

이 방법은 자동으로 호출됩니다. Dropbox 개발자 사이트에서 이미 앱을 만들고 appKey 및 appSecret을 가져 오기를 바랍니다. 이 코드를 응용 프로그램 대리인 NSString * appKey = @ "";

NSString* appSecret = @""; 
     NSString *root = kDBRootDropbox; 
     NSString* errorMsg = nil; 
     if ([appKey rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location != NSNotFound) { 
      errorMsg = @"Make sure you set the app key correctly in DBRouletteAppDelegate.m"; 
     } else if ([appSecret rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location != NSNotFound) { 
      errorMsg = @"Make sure you set the app secret correctly in DBRouletteAppDelegate.m"; 
     } else if ([root length] == 0) { 
      errorMsg = @"Set your root to use either App Folder of full Dropbox"; 
     } else { 
      NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]; 
      NSData *plistData = [NSData dataWithContentsOfFile:plistPath]; 
      NSDictionary *loadedPlist = 
      [NSPropertyListSerialization 
      propertyListFromData:plistData mutabilityOption:0 format:NULL errorDescription:NULL]; 
      NSString *scheme = [[[[loadedPlist objectForKey:@"CFBundleURLTypes"] objectAtIndex:0] objectForKey:@"CFBundleURLSchemes"] objectAtIndex:0]; 
      if ([scheme isEqual:@"db-APP_KEY"]) { 
       errorMsg = @"Set your URL scheme correctly in DBRoulette-Info.plist"; 
      } 
     } 

     DBSession* session = 
     [[DBSession alloc] initWithAppKey:appKey appSecret:appSecret root:root]; 
     session.delegate = self; // DBSessionDelegate methods allow you to handle re-authenticating 
     [DBSession setSharedSession:session]; 
     [DBRequest setNetworkRequestDelegate:self]; 
     // [[DBSession sharedSession]unlinkAll]; 

     if ([[DBSession sharedSession] isLinked]) 
     { 
      isAccountForDropBox = YES; 
     } 
     else{ 
      isAccountForDropBox = NO; 
     } 

// 자동으로 전화를 얻을 것이다이 개폐 URL을 사용한 후.

+0

예. 다행스럽게도 Dropbox에 앱을 만들었고 App-key, Secret key가 있는데, 내 Appdelegate.m에 사용되었지만 사용자 정의 클래스에 코드를 어떻게 구현할 수 있습니까? 너 나 좀 도와 줄 수있어? ? – iTag

+0

나는 그들의 문서를 잘 따라 갔다.하지만 나의 요구 사항은 이것들을 내 커스텀 클래스에 사용해야한다. 그게 다야. – iTag

+0

info plist url 유형 -> url 스키마에서 db-YourAppKey를 추가하면이 메소드는 응용 프로그램 대리인 코드가 필요하지 않습니다. 업데이트 된 문서 만 확인하십시오. – user3663584

0

이 메소드는 AppDelegate.m에서만 응답하며, 외부에서는 사용할 수 없습니다. 는 예를 들어의 ViewController에서, 그런 다음 수업 시간에이 알림을 수신, 당신이 게시물 알림을

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url 
    sourceApplication:(NSString *)source annotation:(id)annotation { 
    if ([[DBSession sharedSession] handleOpenURL:url]) { 
     if ([[DBSession sharedSession] isLinked]) { 
      NSLog(@"App linked successfully!"); 
      // Post Notify here 
      [[NSNotificationCenter defaultCenter] postNotificationName:@"applicationDidLinkWithDropbox" object:self]; 

     } 
     return YES; 
    } 
    // Add whatever other url handling code your app requires here 
    return NO; 
} 

를 사용해야합니다 당신의 ViewController 또는 모든 클래스에서 사용하려면 :

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
               selector:@selector(dropBoxDidLink:) 
                name:@"applicationDidLinkWithDropbox" 
                object:nil]; 
} 
- (void) dropBoxDidLink:(NSNotification *)notification { 
    if ([[notification name] isEqualToString:@"applicationDidLinkWithDropbox"]) { 
    //Handle your task here 

    } 
}