2011-01-14 2 views

답변

11

코드를 살펴보십시오. 방금 SHKFacebook.m/h 파일에서 내 자신의 Send 메서드를 만들었습니다. 도움이 될 것이라고 생각합니다. 여기

-(BOOL) sendWithImage :(NSString*)creativeUrl 
    { 
      self.pendingFacebookAction = SHKFacebookPendingStatus; 

     SHKFBStreamDialog* dialog = [[[SHKFBStreamDialog alloc] init] autorelease]; 
     dialog.delegate = self; 
     dialog.userMessagePrompt = SHKLocalizedString(@"Enter your message:"); 
     dialog.attachment = [NSString stringWithFormat: 
          @"{\ 
          \"name\":\"%@\",\ 
          \"href\":\"%@\",\ 
          \"media\":[{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"}]\ 
          }", 
          item.title == nil ? SHKEncodeURL(item.URL) : SHKEncode(item.title), 
          SHKEncodeURL(item.URL), 
          creativeUrl, 
          SHKEncodeURL(item.URL) 

         ]; 
    dialog.defaultStatus = item.text; 
    dialog.actionLinks = [NSString stringWithFormat:@"[{\"text\":\"Get %@\",\"href\":\"%@\"}]", 
          SHKEncode(SHKMyAppName), 
          SHKEncode(SHKMyAppURL)]; 
    [dialog show]; 
    return YES; 

} 

내가 GitHub의에서 최신 sharekit를 사용하고 그것을

SHKFacebook *fb =[[SHKFacebook alloc]init]; 

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@iphone/photo?id=%d",[SplashViewController getBaseURL],[photoId intValue]]]; 
    fb.item = [SHKItem URL:url title:[dicResult valueForKey:@"Caption"]]; 
    //fb.shareType = SHKShareTypeURL; 
    fb.quiet = YES; 
    [TedryUITabBarController updateProgress:10 totalByteToSent:11 message:@"Sharing on facebook"]; 
    [fb sendWithImage:[dicResult valueForKey:@"CreativeURL"] :@""]; 
+1

좋은 답변입니다. – justicepenny

+0

scompt, 여기에 코드를 시작하는 데 도움을 줄 수 있습니까? 항목은 어디에 있습니까? 나는 sharekit이 아이템에 관한 것이라고 생각합니다 ... 어떻게 sendWithImage를 호출합니까 - 샘플을 보여줄 수 있습니까? 감사! –

+0

Youve는 코드의 큰 덩어리를 놓쳤으므로 해결 방법은 작동하지 않습니다. – daidai

4

를 사용하는 방법입니다. 실제로, 당신은 다만 열쇠 "그림"와 더불어 연결의 주문 가치로 URL를 놓았다

NSString *urlImage = @"http://someurl.com/someimage.jpg"; 
[linkItem setCustomValue:urlImage forKey:@"picture"]; 

그것은 나를 위해 작동한다.

+0

나를 위해 작동하지 않았습니다 ... – daidai

+0

소스 코드보기 :'SHKShareTypeURL = SHKShareTypeURL'을 설정하고' item.URL'. 나를 위해 잘 일했다. –

+0

이것은 forKey : @ "image"대신 – Eric

5

다른 답변에 문제가있는 사용자에게는 약간 더 간단 할 수 있습니다 (원칙적으로 원칙적으로 동일 함). 소스 URL 및 링크 URL :

[item setCustomValue:@"Your caption" forKey:@"caption"]; 
[item setCustomValue:@"Your description" forKey:@"description"]; 
[item setCustomValue:@"Your image URL" forKey:@"mediaSrc"]; 
[item setCustomValue:@"Your image link" forKey:@"mediaHREF"]; 

주 하단에있는 이미지에 필요한 두 개의 값을 :

같은, 당신의 품목에 사용자 정의 값을 추가합니다. 다음과 같이 다음, 그 값을 사용 SHKFacebook.m에서 "전송"방법을 수정해야합니다

// ... 
if (item.shareType == SHKShareTypeURL) 
{ 
    self.pendingFacebookAction = SHKFacebookPendingStatus; 

    SHKFBStreamDialog* dialog = [[[SHKFBStreamDialog alloc] init] autorelease]; 
    dialog.delegate = self; 
    dialog.userMessagePrompt = SHKLocalizedString(@"Enter your message:"); 

    // with image... 
    dialog.attachment = [NSString stringWithFormat: 
         @"{\ 
         \"name\":\"%@\",\ 
         \"href\":\"%@\",\ 
         \"caption\":\"%@\",\ 
         \"description\":\"%@\",\ 
         \"media\":[\ 
          {\ 
           \"type\": \"image\",\ 
           \"src\": \"%@\",\ 
           \"href\": \"%@\"\ 
          }]\ 
         }", 
         item.title == nil ? SHKEncodeURL(item.URL) : SHKEncode(item.title), 
         SHKEncodeURL(item.URL), 
         [item customValueForKey:@"caption"], 
         [item customValueForKey:@"description"], 
         [item customValueForKey:@"mediaSrc"], 
         [item customValueForKey:@"mediaHREF"] 
         ]; 

    dialog.defaultStatus = item.text; 
    dialog.actionLinks = [NSString stringWithFormat:@"[{\"text\":\"Get %@\",\"href\":\"%@\"}]", 
          SHKEncode(SHKMyAppName), 
          SHKEncode(SHKMyAppURL)]; 
    [dialog show]; 

} 
// ... 

그리고 jumponadoughnut 에 의해 주어진 링크는 내가 할 수 없었다 (사용할 수있는 필드의 최종 목록입니다 내 대리인이 충분히 높지 않기 때문에 투표하십시오) : http://developers.facebook.com/docs/guides/attachments

+0

을 사용할 때 SHKEncode 또는 SHKEncodeURL 또는 다른 방법을 사용하여 이러한 사용자 정의 값을 이스케이프해야합니다. 그렇지 않으면 유효하지 않은 JSON 데이터로 끝날 수 있습니다 – PetrV

관련 문제