2012-01-16 63 views
3

我是一個新手,想弄清楚如何修改Foursquare iOS API「BZFoursquare」在這裏找到:https://github.com/baztokyo/foursquare-ios-api 在他們的例子中,他們使用了一個全功能的ViewController。不過,我將擁有多個ViewController,因此希望擁有一個帶有常用代碼的AppController。我如何需要在ios5下執行此操作?Foursquare iOS API

感謝您的任何幫助。

回答

4

看到這個鏈接https://github.com/Constantine-Fry/Foursquare-API-v2/tree/master/Foursquare2-iOS。很容易整合iPhone的foursquare API。

嗨Marco, 將Foursquare2文件夾添加到您的項目中,並檢查視圖控制器中的身份驗證。請參閱以下代碼。它會幫助你。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.title = @"Foursquare"; 
    //check the authentication 
    if ([Foursquare2 isNeedToAuthorize]) { 
     //If needed show the webview 
     webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; 
     NSString *url = [NSString stringWithFormat:@"https://foursquare.com/oauth2/authenticate?display=touch&client_id=%@&response_type=code&redirect_uri=%@",OAUTH_KEY,REDIRECT_URL]; 
     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; 
     [webView loadRequest:request]; 
     [webView setDelegate:self]; 
     [self.view addSubview:webView]; 
     [webView release]; 
     mTableView.hidden = YES; 
    }else{ 
     //Show your view 
     mTableView.hidden = NO; 
     [Foursquare2 searchVenuesNearByLatitude:@"40.763" longitude:@"-73.990" accuracyLL:nil altitude:nil accuracyAlt:nil query:@"" limit:@"15" intent:@"" callback:^(BOOL success, id result){ 
      if (success) { 

       tableData = [[FoursquareParser parseSearchVenuesResultsDictionary:(NSDictionary*)result] retain]; 
       [mTableView reloadData]; 

      } 
     }]; 

    } 
} 
+0

如何我需要集成這個API,如果我想使用故事板(SDK 4.1)? – Marco 2012-01-21 23:07:47

0

您還可以使用oAuth登錄foursquare,因爲它很容易實現。在oAuth 2.0中,您必須獲取訪問令牌並使用該訪問令牌才能獲取用戶詳細信息,如朋友和個人資料信息。 oAuth是2步驗證方法,詳細實現,因爲你是新手,所以我找到了一個很好的教程,Login with Foursquare