ShareSDK is a service gives mobile apps sharing capabilities in minutes.
Production description:
ShareSDK is a service gives mobile apps sharing capabilities in minutes, it provides instant track posting to 40+ major social platforms with social analytics to developers understand the social behavior of their apps with our social analytics dashboard.
Open Github download the C2DXShareSDKSample projects. The project C2DXShareSDK folder copy to your project.
Open the “AppDelegate.cpp” file, import the header file “C2DXShareSDK.h”. Such as:
In AppDelegate :: applicationDidFinishLaunching method, add the following code to initialize ShareSDK and configure the social platform information.
Note: where the configuration items in social platform configuration information, refer to Social Platform Configuration Item Description document.
First, create a structure to share content, as follows:
Then the content object incoming share interfaces. such as:
shareResultHandler is callback method, which is defined as follows:
To get the authorized users information by call the C2DXShareSDK::geUserInfo method . Code is as follows:
getUserResultHandler is callback method, which is defined as follows:
Login ShareSDK http://sharesdk.cn official website to download and extract the latest version of the SDK. If you have not downloaded yet, please click here to download or access http://sharesdk.cn/Download. After extracting the following diagram:
The ShareSDK_vX.XX (XXX represents SDK version number) directory are copied to your cocos2d-x project. Figure:
The ShareSDK into the project, and add the appropriate dependencies. This step can refer to: iOS Quick Integration Guide in the first, the second step. After execution, as shown below:
Open the “AppController.mm” file, add ShareSDK.h header file:
Add handleOpenURL method, as follows:
In the integrated WeChat, QQ, Google*, Pinterest, RenRen platform, you need to import the relevant type. Code is shown below:
<pre>
#import “WXApi.h” //WeChat
#import “WBApi.h” //Tencent Weibo
#import <TencentOpenAPI/QQApiInterface.h> //QQ Connect
#import <TencentOpenAPI/TencentOAuth.h> //QQ Connect
#import <RennSDK/RennSDK.h> //人人网
#import <Pinterest/Pinterest.h> //Pinterest
#import <GoogleOpenSource/GoogleOpenSource.h> //Google*
#import <GooglePlus/GooglePlus.h> //Google+
@implementation AppController
//……
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:launchOptions {
//……
//Import WeChat Class
];
//Import Tencent Weibo Class
];
//Import QQ Class
tencentOAuthCls:];
//Import RenRen Class
];
//Import Pinterest Class
];
//Import Google+ Class
shareClass:];
//……
}
</pre>
h1. Integration for Android
**Note: This section describes how to integrate ShareSDK into coco2d-x with**custom JNI codes**, if you want to find ”**how to integrate ShareSDK with pure Java codes**”, please click HERE . And if you want to find ”**how to integrate ShareSDK with plugin-x**”, please click HERE .
h2. Integration Steps
1 Download the latest version of ShareSDK from our official website and extract it.
2 Refer to the “”Five Steps to Integrate ShareSDK“:https://github.com/ShareSDKPlatform/ShareSDK-for-Android/wiki/Five-Steps-to-Integrate-ShareSDK” chapter, use “**copy jars and resources into your project**” way to import ShareSDK to your project. After these two steps, your project should include the followings: Java source codes of OnekeyShare. If you integrate Wechat or Yixin, your project should include the package wxapi or yxapi. Resources of ShareSDK and OnekeyShare must have been added into your “res” directory. Jars of ShareSDK must have been copied into your “libs” directory. Besides resources of cocos2d-x, there is a SahreSDK.xml file in your “assets” directory.
3 Refer to the “”Five Steps to Integrate ShareSDK“:https://github.com/ShareSDKPlatform/ShareSDK-for-Android/wiki/Five-Steps-to-Integrate-ShareSDK” chapter, modify the “AndroidManifest.xml” file.
4 Applications information in “ShareSDK.xml” are public keys for demonstration. Please change the information of each platform in this file to your application’s refering to the “”Five Steps to Integrate ShareSDK“:https://github.com/ShareSDKPlatform/ShareSDK-for-Android/wiki/Five-Steps-to-Integrate-ShareSDK” chapter.
5 Pull the source codes on Github , and copy the followings into your project: Copy “cn.sharesdk.ShareSDKUtils” into your “src”. Copy “libs/armeabi” to your “libs”.
6 Open the class you extend from Cocos2dxActivity, add the following line into its onCreate method:
<pre>
ShareSDKUtils.prepare;
</pre>
h2. Explanation of Java Codes
Basically there is only a ShareSDKUtils Java class, and what you have to do in Java codes is adding the**prepare* in your subclass of Cocos2dxActivity. However, if you want to add more parameters of sharing (the example on github only provides very few parameters to share), you may have to modify the following methods:
nativeMapToJavaMap(HashMap)
This method is to transfer the name of the parameters to share from the JNI type to the Java types. If you add the share parameter in native codes, you need to modify this method, add a new rule to translate the name of this parameter to ShareSDK. HERE is the table lists the name of the share parameters in ShareSDK.
This method calls OnekeyShare module of ShareSDK, like the method above, if you want to modify the share parameters in native codes, you may need to modify this method.
It is important to note that ShareSDKUtils.prepare() must be called in the main thread, and before any operation of ShareSDK. Otherwise it will result in an error in ShareSDKUtils initializing.
Using custom JNI codes is not an encouraged way of Android platform to integrating ShareSDK, since you have to add a ton of native-java reflection code which is inefficient and prone to errors. But this method can shield the differences between the platforms by c/c++ codes, and also be complementary to the plugin-x.
Native codes are basically the reflection between native and java codes. However, like Java codes, if you want to modify the native codes, you may need to be carefully with the following methods:
These three methods are java to native action callbacks, don’t change their names.
These two methods process the transform between HashMap and CCDictionary.
This is not a necessary method in Android, since we have a more convenient way to configure your applications information in the file “ShareSDK.xml”.