2014-07-14 3 views
0

안녕하세요. 내 애플리케이션에 안녕하세요. Facebook을 통해 내 애플리케이션을 공유 할 수 있습니다. 그래서 내 프로젝트에 Facebook framework을 추가했으며 번들 ID를 내 Facebook에 추가했으며 앱 ID를 얻었지만 문제는 내가이 앱을 공유 할 수 없음을 나타냅니다.facebook을 통한 앱 공유가 작동하지 않습니다.

An error occurred. Please try again later 

내 자극기에 이와 같이 표시되는 이유는 무엇입니까? 내 장치에 Facebook App이 작동하지만 정상적으로 작동하지 않는 경우 Facebook App에 이와 같은 오류가 표시됩니다. 이 문제를 해결하는 방법을 알려주십시오.

- (IBAction)share:(id)sender { 
    FBLinkShareParams *params = [[FBLinkShareParams alloc] init]; 
    params.link = [NSURL URLWithString:@"url/"]; 

// If the Facebook app is installed and we can present the share dialog 
if ([FBDialogs canPresentShareDialogWithParams:params]) { 

    // Present share dialog 
    [FBDialogs presentShareDialogWithLink:params.link 
            handler:^(FBAppCall *call, NSDictionary *results, NSError *error) { 
             if(error) { 
              // An error occurred, we need to handle the error 
              // See: https://developers.facebook.com/docs/ios/errors 
              NSLog(@"Error publishing story: %@", error.description); 
             } else { 
              // Success 
              NSLog(@"result %@", results); 
             } 
            }]; 

    // If the Facebook app is NOT installed and we can't present the share dialog 
    } else { 
    // FALLBACK: publish just a link using the Feed dialog 

    // Put together the dialog parameters 
    // Put together the dialog parameters 
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
            @"My appname", @"name", 
            @"test share.", @"caption", 
            @"sample.", @"description", 
            @"myrul", @"link", 

            nil]; 

    // Show the feed dialog 
     [FBWebDialogs presentFeedDialogModallyWithSession:nil 
              parameters:params 
               handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) { 
                if (error) { 
                 // An error occurred, we need to handle the error 
                 // See: https://developers.facebook.com/docs/ios/errors 
                 NSLog(@"Error publishing story: %@", error.description); 
                } else { 
                 if (result == FBWebDialogResultDialogNotCompleted) { 
                  // User canceled. 
                  NSLog(@"User cancelled."); 
                 } else { 
                  // Handle the publish feed callback 
                  NSDictionary *urlParams = [self parseURLParams:[resultURL query]]; 

                  if (![urlParams valueForKey:@"post_id"]) { 
                   // User canceled. 
                   NSLog(@"User cancelled."); 

                  } else { 
                   // User clicked the Share button 
                   NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]]; 
                   NSLog(@"result %@", result); 
                  } 
                 } 
                } 
               }]; 

             } 
            } 


    - (NSDictionary*)parseURLParams:(NSString *)query { 
     NSArray *pairs = [query componentsSeparatedByString:@"&"]; 
     NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; 
    for (NSString *pair in pairs) { 
     NSArray *kv = [pair componentsSeparatedByString:@"="]; 
     NSString *val = 
     [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
     params[kv[0]] = val; 
     } 
    return params; 
    } 

위의 코드를 사용하여이 문제를 해결하는 방법을 알려 주셨습니다.

감사합니다.

답변

0

이 코드를 공유 응용 프로그램에 사용하십시오. SLComposeViewController의 사용을 위해

-(void)facebook 
{ 

    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { 


     SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 


     SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){ 
      if (result == SLComposeViewControllerResultCancelled) { 

       NSLog(@"Cancelled"); 

      } 
      else 
      { 
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congratulations!" message:@"Successfully posted to facebook Wall." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 

       [alert show]; 

       [Flurry logEvent:@"Share screen - Successfully posted on Facebook"]; 
      } 

      [controller dismissViewControllerAnimated:YES completion:Nil]; 
     }; 

     controller.completionHandler =myBlock; 
     NSString *str=[NSString stringWithFormat:@" I am using App for my iPhone. You too can download it from here"]; 
     [controller setInitialText:str]; 
     [self presentViewController:controller animated:YES completion:Nil]; 
    } 
    else{ 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!"message:@"Please add Facebook account in settings menu" delegate:self cancelButtonTitle:Nil otherButtonTitles:@"Ok", nil]; 
      alert.tag=100; 
     [alert show]; 
    } 
} 

, 당신은 사회 프레임 워크을 추가해야합니다. 그것은 에서 귀하의 페이스 북 계정을 가져오고 SLComposeViewController을 통해 앱 링크를 공유 할 수 있습니다. 및

당신은보다에서에 이미지 나 URL을 추가하려면 :

[composeController addImage:[UIImage imageNamed:@"image.png"]]; 
[composeController addURL: [NSURL URLWithString:@"apple.com"]]; 
+0

는 않습니다이 코드 중량 알려주십시오과 중량이있는 컨트롤러 SLComposeViewController 내가 이미 페이스 북 아이디 모든게하지만 아직되지 추가 한이 – user3819340

+0

때문이다 woriking – user3819340

+0

내 대답을 다시 확인하십시오. – iBhavin

관련 문제