2013-02-28 4 views
9

나는에 대한 내 iOS 앱을 완료하지만 두 개의 버튼을 추가해야했습니다 : 나는 간단한 몇 가지를 찾을 것이라고 가정 'facebook on us'버튼을 iOS 앱에 추가하려면 어떻게해야하나요?

  • 트위터
  • 에 우리를 따르라

    • 페이스 북에 우리를 따르라 여기에 예제가 있지만 전혀 대답을 찾지 못한 것에 놀랐다.

      나는 앞으로 몇 시간을 알아 내려고 할 수있을 것이라고 확신하지만 시간을 절약하는 데 도움이 될 것이라고 생각했습니다.

      단지보기 컨트롤러 (XCode 4.5.1, iOS 6)의 버튼으로 이동하는 코드를 찾고 있습니다.

      내가 제공해야 할 수도있는 유일한 변수는 회사의 Facebook 계정 이름입니다.

      제안 사항? (미리 감사드립니다!)

    +2

    버튼이 Facebook 로그인 세부 정보를 즉시 요청해야합니까? 아니면 Facebook 페이지를 회사 페이지에 열어야합니까? –

    +0

    사용자가 이미 페이스 북에 로그인 한 경우 (iOS 내에서 지속될 수 있다고 가정), 페이스 북 페이지에 이미있는 것처럼 행동을 에뮬레이트하고 자동으로 좋아요 버튼을 클릭하게하고 싶습니다. 그래서 내가 추가 할 버튼 하나를 클릭하면 페이스 북 페이지를 자동으로 '좋아할 것'이라고 생각합니다. – dcb

    답변

    1

    페이스 북 버튼을 추가하는 방법에 대한 페이지를 가지고,이 링크를

    https://developers.facebook.com/docs/reference/plugins/follow/

    을보고 twitters는

    https://support.twitter.com/articles/20164833-how-to-add-the-follow-button-to-your-website

    그것이

    도움이되기를 바랍니다 여기에있다
    +0

    고맙습니다 mart87. 그게 좋겠지 만 페이스 북 링크를 따라 가면 코드 생성기가 iOS 앱에서 객관적인 것을 어떻게 도와 줄 수 있는지 알지 못한다. 즉, 웹 사이트에 버튼을 추가하지 않습니다. iPhone 앱에 추가하고 있습니다. 더 나은 방법을 찾지 못하면 아마 UIWebView를 사용할 것입니다. 다시 한 번 감사드립니다! – dcb

    16

    먼저 Facebook의 URL 스키마는 fb://profile/<yourpageid> (source). 이 구조체가있는 URL을 사용하면 Facebook 앱이 열립니다 (설치된 경우).

    More on iOS URL schemes. 당신의 버튼을 탭하면

    , 당신은 페이스 북이 설치되어 있는지 확인할 수 있습니다 트위터를 들어

    -(IBAction)fbButtonTap:(id)sender { 
        NSURL *fbURL = [[NSURL alloc] initWithString:@"fb://profile/<yourpageid>"]; 
        // check if app is installed 
        if (! [[UIApplication sharedApplication] canOpenURL:fbURL]) { 
         // if we get here, we can't open the FB app. 
         fbURL = ...; // direct URL on FB website to open in safari 
        } 
    
        [[UIApplication sharedApplication] openURL:fbURL]; 
    } 
    

    , 당신은 동일한 기본 단계를 수행합니다. iOS 용 Twitter URL 체계는 twitter://user?id=12345 또는 twitter://user?screen_name=yourname (source)입니다. 트위터 앱이 설치되어 있지 않은 경우에도 사파리에서 트위터 프로필을 열었습니다.

    직접 조치를 취하는 것에 대해서는 기기에 설치된 다른 애플리케이션에 대한 고유 한 지식이 없으므로 사용자가 직접 조치 할 수 있다고 생각하지 않습니다. 귀하가 할 수 있다고 생각하는 최선의 방법은 사용자를 각 해당 계정으로 안내하는 것입니다.

    0

    내 앱의 커뮤니티 페이지를 좋아하는 사용자에게 표시하는 코드입니다.

    코드 내부에 표시 할 위치에 _webview를 추가 할 수 있습니다.

    facebook은 webview 내부 페이지를 보여주는 코드를 제공합니다.

    -(void)likeus 
    { 
    
    
    
    _webview =[[UIWebView alloc] initWithFrame:CGRectMake(14,94, 292, 250)]; 
    AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    //Load web view data 
    NSString *strWebsiteUlr [email protected]"http://www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2Fenbuyukkim&width=292&height=258&show_faces=true&colorscheme=dark&stream=false&border_color&header=false&appId=433294056715040"; 
    
    // Load URL 
    
    //Create a URL object. 
    NSURL *url = [NSURL URLWithString:strWebsiteUlr]; 
    
    //URL Requst Object 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
    
    //Load the request in the UIWebView. 
    [_webview loadRequest:requestObj]; 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [button addTarget:_webview 
          action:@selector(removeFromSuperView) 
    forControlEvents:UIControlEventTouchUpInside]; 
    button.frame = CGRectMake(270.0, 80.0, 30.0, 30.0); 
    [button setBackgroundImage:[UIImage imageNamed:@"cross.png"] forState:UIControlStateNormal]; 
    [_webview addSubview:button]; 
    
    } 
    
    0

    내가 찾고있는 것이 맞는지 확실하지 않지만 다른 스레드에서 스택 오버플로가 발생했을 때 해결책을 찾은 것 같습니다.

    이 스레드에서 살펴 보자 : Adding the Facebook Like Button in an iPhone App

    희망이 당신을하는 데 도움이!

    1

    SLRequest 누군가가 나를 팔로우 할 수 있습니다. 이 기능은 iOS 5에서만 작동하지만 Facebook에서는 작동하지 않습니다.

    이 배경 스레드에서 호출되어 있는지 확인 누군가가 트위터에 당신을 따라 할 SLRequest의 예 :

    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 
        ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 
    
        [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) { 
    
         if (granted) { 
    
          // Get the list of Twitter accounts. 
          NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; 
    
          // For the sake of brevity, we'll assume there is only one Twitter account present. 
          // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present. 
          if ([accountsArray count] > 0) { 
           // Grab the initial Twitter account to tweet from. 
           ACAccount *twitterAccount = [accountsArray objectAtIndex:0]; 
    
           NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init]; 
           [tempDict setValue:@"Your twitter name" forKey:@"screen_name"]; 
           [tempDict setValue:@"true" forKey:@"follow"]; 
    
           SLRequest *followRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1/friendships/create.json"] parameters:tempDict]; 
    
           [followRequest setAccount:twitterAccount]; 
           [followRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
            NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]]; 
            NSLog(@"%@", output); 
            if (error) { 
             dispatch_async(dispatch_get_main_queue(), ^{ 
              //Update UI to show follow request failed 
             }); 
            } 
            else { 
             dispatch_async(dispatch_get_main_queue(), ^{ 
              //Update UI to show success 
             }); 
            } 
           }]; 
          } 
         } 
        }]; 
    

    와 페이스 북에 대한 당신은 단지 그것의 일부를 변경하고 자신의 API를보고 있고 요청 URL을 변경하십시오.

    관련 문제