Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Code Snippets

Social Media Share content in iOS

Paste down any little snippets or request a new one.

Social Media Share content in iOS

Postby juaxix » 18 Oct 2011, 17:19

In this ,my second guide, i want to show you how to set up the iOS ShareKit in your games or applications made with Shiva. :D
Spetial thanks to Scribe and vklymenko: http://www.stonetrip.com/developer/forum/viewtopic.php?f=40&t=22363

*********************************
1.- CREATE THE AI FUNCTIONS
*********************************

First create the functions in your MainAI to share the contents. There are three types of contents that can be shared: links, texts and images. For the third part I am leaving a hole to be filled by another genious of Shiva that can tell us how to save the current render image or a rendermap into a file to latest use from an external function.

For the rest of the cases we have to create each event function in MainAI:

--- Share a text in social networks
Code: Select all
function OnShareKitTextCall ( text )
-- empty function
end


*********************************
2.- ADD AND FIX SHAREKIT IN XCODE
*********************************
To call these functions from a hud button component create a hud action that calls a hud OnSendSocialMedia and inside this one create de string and url and then call the "OnShareKitTextCall ( text )" function with these data.


Export the game, create the XCode Project, download the ShareKit from http://getsharekit.com/install/
you can follow their tut if you want...
now, drag and drop Classes/ShareKit to your project and COPY the files, then drag and drop the SystemConfiguration, Security and MessageUI frameworks from the Sharekit original project WITHOUT COPY, just "Create folder references..." activated.
Now you have to fix 2 compilation errors, both to change from C++ to C standards,
the error: "'for' loop initial declaration used outside C99 mode", is solved by extracting the int from
---
for (int i=...)
---
and declare it before the 'for' loop. (int i; -> outside of the for (__))

*********************************
3.- CREATE THE HANDLE FUNCTIONS
*********************************
Now you can create the functions, the simplest part.

- The external declaration (link with Shiva project)

-+++ File: S3DEngine_Wrapper.h (add before #endif): ++++
Code: Select all
extern bool         S3DEngine_Game_ShowShareKitText           ( );
extern const char  *S3DEngine_ShareKit_GetTextToShare         ( );
extern void         S3DEngine_Game_SetShowShareKitTextFalse   ( );

-++++++++++++++++++++++++++++++++++++++++++

-+++ File: S3DEngine_Wrapper.cpp (add after #includes): ++++
Code: Select all
static bool bGameShowShareKitText = false;
static char textToShare[500] = "I love Games"; //default text

-++++++++++++++++++++++++++++++++++++++++++

in the same file (S3DEngine_Wrapper.cpp), add, before function S3DEngine_iPhone_LoadPack:
Code: Select all
void ShareKitTextCall ( unsigned char _iArgumentCount, const void *_pArguments, void *_pUserData )
{
    bGameShowShareKitText = true;
    if ( _pArguments && ( _iArgumentCount == 1 ) )
    {
        const S3DX::AIVariable *pVariables = (const S3DX::AIVariable *)_pArguments ;
       
        if ( pVariables[0].GetType ( ) == S3DX::AIVariable::eTypeString )
        {
            strcpy ( textToShare, pVariables[0].GetStringValue ( ) ) ;
        }
    }
}



in the same file (S3DEngine_Wrapper.cpp), add, inside the S3DEngine_iPhone_LoadPack function:

Code: Select all
    S3DClient_InstallCurrentUserEventHook   ( "MainAI", "onShareKitTextCall",  ShareKitTextCall, NULL ) ;


where MainAI is the name of the AI where you have added the events called.

At the end of this file (S3DEngine_Wrapper.cpp) add:
Code: Select all
extern "C" bool S3DEngine_Game_ShowShareKitText( ){
    return bGameShowShareKitText;
}


extern "C" void S3DEngine_Game_SetShowShareKitTextFalse (){
    bGameShowShareKitText = false;
}


extern "C" const char *S3DEngine_ShareKit_GetTextToShare()
{   
    return textToShare;
}



- The call inside the loop (link with the external)
S3DEngine_EAGLView.h:, before @end:
Code: Select all
- (void)showShareKitText;


S3DEngine_EAGLView.m, search for drawView function and after display/hide AdMob add:
Code: Select all
if (S3DEngine_Game_ShowShareKitText() ){
   S3DEngine_Game_SetShowShareKitTextFalse();
   [self showShareKitText];
}



- Call to ShareKit Framework:
Also in S3DEngine_EAGLView.m, just before the showVirtualKeyboard definition,add:
Code: Select all

- (void) showShareKitText {
    SHKItem *itemToShare = [SHKItem text:[[NSString alloc] initWithUTF8String:S3DEngine_ShareKit_GetTextToShare()]];
    SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:itemToShare];
    [actionSheet showInView:self.viewPrintFormatter.view];
}

User avatar
juaxix
Gold Boarder
Gold Boarder
 
Posts: 312
Location: Spain

Return to Code Snippets