Unity3D Facebook SDK for iOS Integration 5. 친구에게 자랑하기

 2013년 11월에 했던것을 잊어먹고 있다가 이제야 정리하네요. 유니티3D iOS 페이스북 친구 목록 얻기 및 친구에게 초대 요청하기를 정리했었습니다. 이번에는 친구에게 자랑하기를 정리해봅니다.


 먼저 iOS 플러그인 소스입니다.

// iOSFacebookPlugin.h
- (void) requestBrag:(NSString*)strTitle
             caption:(NSString*)strCaption
         description:(NSString*)strDescription
             picture:(NSString*)strPicture;

// iOSFacebookPlugin.mm
extern "C"

{
...
    void iOSRequestBrag(const char* pszTitle, const char* pszCaption, const char* pszDescription, const char* pszPicture)
    {
        NSString* strTitle = [NSString stringWithUTF8String:pszTitle];
        NSString* strCaption = [NSString stringWithUTF8String:pszCaption];
        NSString* strDescription = [NSString stringWithUTF8String:pszDescription];
        NSString* strPicture = [NSString stringWithUTF8String:pszPicture];
        [[iOSFacebookPlugin sharediOSFacebookPlugin] requestBrag:strTitle
                                                         caption:strCaption
                                                     description:strDescription
                                                         picture:strPicture];
    }
}


@implementation iOSFacebookPlugin
...

- (void) requestBrag:(NSString*)strTitle
             caption:(NSString*)strCaption
         description:(NSString*)strDescription
             picture:(NSString*)strPicture
{
    NSString* linkURL = [NSString stringWithUTF8String:""];
    // Prepare the native share dialog parameters
    FBShareDialogParams *shareParams = [[FBShareDialogParams alloc] init];
    shareParams.link = [NSURL URLWithString:linkURL];
    shareParams.name = strTitle;
    shareParams.caption= strCaption;
    shareParams.picture= [NSURL URLWithString:strPicture];
    shareParams.description = strDescription;
    
    if ([FBDialogs canPresentShareDialogWithParams:shareParams]){
        
        [FBDialogs presentShareDialogWithParams:shareParams
                                    clientState:nil
                                        handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                            if(error) {
                                                NSLog(@"Error publishing story.");
                                            } else if (results[@"completionGesture"] && [results[@"completionGesture"] isEqualToString:@"cancel"]) {
                                                NSLog(@"User canceled story publishing.");
                                            } else {
                                                NSLog(@"Story published.");
                                            }
                                        }];
        
    }else {
        
        // Prepare the web dialog parameters
        NSDictionary *params = @{
                                 @"name" : shareParams.name,
                                 @"caption" : shareParams.caption,
                                 @"description" : shareParams.description,
                                 @"picture" : strPicture,
                                 @"link" : linkURL
                                 };
        
        // Invoke the dialog
        [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                               parameters:params
                                                  handler:
         ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
             if (error) {
                 NSLog(@"Error publishing story.");
             } else {
                 if (result == FBWebDialogResultDialogNotCompleted) {
                     NSLog(@"User canceled story publishing.");
                 } else {
                     NSLog(@"Story published.");
                 }
             }}];
    }
}

@end

 자랑할 때 타이틀과, 캡션, 설명, 이미지를 인자로 넘겨주고 있습니다. 추가로 웹링크도 설정이 가능하지만 일단 이 포스팅에서는 제외했습니다. 아래는 유니티3D쪽 컴포넌트 소스입니다.


//iOSManager.cs


public class iOSManager : MonoBehaviour 
{
...

[DllImport("__Internal")]
private static extern void iOSRequestBrag(string strTitle, string strCaption, string strDescription, string strPicture);


public void RequestBrag(string strTitle, string strCaption, string strDescription, string strPicture)
{
iOSRequestBrag(strTitle, strCaption, strDescription, strPicture);
}

//TestGUI.cs

void OnGUI()

{
...

fYpos += 50;
if (GUI.Button (new Rect(0, fYpos, 100, 50), "Request Brag") == true)
{
iOSManager.GetInstance().RequestBrag("WestWoodForever"
, "Unity3D iOS Facebook"
, "Request Brag"
, "http://lh4.googleusercontent.com/-DrSTrtL3Pl8/AAAAAAAAAAI/AAAAAAAANbQ/8wxo_-667bM/s512-c/photo.jpg");
}


 지금은 간단하게 호출해주고 있지만 자신의 점수등을 인자에 포함해서 자랑 스트링을 넘겨주면 되겠네요. Request Brag 버튼을 누르면 아래 그림과 같이 팝업 다이얼로그가 뜨고 내용을 입력 후 공유합니다.



 그러면 아래와 같이 테스트 결과를 확인할 수 있습니다.


참고
페이스북 개발자 센터 iOS 자랑하기와 피드
페이스북 깃허브 iOS Smash 샘플

댓글

이 블로그의 인기 게시물

'xxx.exe' 프로그램을 시작할 수 없습니다. 지정된 파일을 찾을 수 없습니다.

goorm IDE에서 node.js 프로젝트로 Hello World Simple Server 만들어 띄워보기

애드센스 수익을 웨스턴 유니온으로 수표대신 현금으로 지급 받아보자.