2、下载sharesdk-cocos2dx-3.x版 和 androID 、ios包
3、ios平台 --添加最新的sharesdk-ios
1-加入平台库
SystemConfiguration.framework ,
QuartzCore.framework ,
CoreTelephony.framework ,
libicucore.dylib ,
libz.1.2.5.dylib ,
Security.framework
libstdc++.dylib --qq和空间
libsqlite3.dylib --qq和空间
3-1配置url schemes (新浪微博如果配置,则为sso免登录)
实力: QQ05FB8B52,wx4868b35061f87885
说明:
QQ的AppID,其格式为:”QQ” + AppID的16进制(如果appID转换的16进制数不够8位则在前面补0,如转换的是:5FB8B52,则最终填入为:QQ05FB8B52 注意:转换后的字母要大写)
在微信开放平台(http://open.weixin.qq.com/ )注册应用并取得应用的AppID,然后打开下图位置,在URL Types中添加微信AppID
配置新浪微博、Facebook的SSO(如不需要免帐号登录可跳过
登录新浪微博和facebook的开放平台,获取AppID 。新浪微博的url scheme的设置格式为wb+AppID,facebook的设置格式为fb+AppID。具体参考下图:
3-2
添加短信分享、邮件分享、打印、拷贝(如不需要可跳过)
//连接短信分享
[ShareSDK connectSMS];
//连接邮件
[ShareSDK connectMail];
//连接打印
[ShareSDK connectAirPrint];
//连接拷贝
[ShareSDK connectcopy];
3-3 ipad分享
功能接口创建一个容器对象并调用容器对象的setIPadContainer系列方法来设置iPad版显示容器。 一般而言,我们会建议使用一个比较小的、作为当前vIEwController 所控制的vIEw 的subvIEw 来作为“锚点”,来设置 container。例如一个已有的button。这样分享界面或者授权界面才能正确显示。调用接口如下:
ID<ISSContainer> container = [ShareSDK container];
[container setIPadContainerWithVIEw:sender arrowDirect:UIPopoverArrowDirectionUp];
然后将container对象传入showShareActionSheet的第一个参数中,如:
//d出分享菜单
[ShareSDK showShareActionSheet:container
shareList:nil
content:publishContent
statusbarTips:YES
authOptions:nil
shareOptions:nil
result:^(ShareType type,SSResponseState state,ID<IssplatformShareInfo> statusInfo,ID<IcmerrorInfo> error,BOol end) {
if (state == SSResponseStateSuccess)
{
NSLog(@"分享成功");
}
else if (state == SSResponseStateFail)
{
NSLog(@"分享失败,错误码:%d,错误描述:%@",[error errorCode],[error errorDescription]);
}
}];
4、导入跨平台包
修改:C2DXShareSDK.cpp
C2DXiOSShareSDK::open(CCString::createWithFormat("%s",appKey),useAppTrusteeship);
第二部:
AppController.mm
头文件
#import <ShareSDK/ShareSDK.h>
//微信
#import "WXAPI.h"
//qq互联
#import <TencentopenAPI/QQAPIInterface.h>
#import <TencentopenAPI/TencentOAuth.h>
在 dIDFinishLaunchingWithOptions 中
//导入微信
[ShareSDK importWeChatClass:[WXAPI class]];
//导入qq互联
[ShareSDK importQQClass:[QQAPIInterface class] tencentOAuthCls:[TencentOAuth class]];
处理handleOpenURL
- (BOol)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [ShareSDK handleOpenURL:url sourceApplication:nil annotation:nil wxDelegate:nil];
}
- (BOol)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(Nsstring *)sourceApplication annotation:(ID)annotation
{
return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:nil];
}
--------------------------------------------
在AppDelegate.h中
private:
//初始化平台配置
voID initPlatformConfig();
在AppDelegate.cpp中
头文件
#include "C2DXShareSDK.h"
using namespace cn::sharesdk;
init方法:
//初始化ShareSDK
//C2DXShareSDK::open("API20",false);
C2DXShareSDK::open(CCString::create("API20"),false);
this->initPlatformConfig();
//新浪微博,qq和空间,微信
voID AppDelegate::initPlatformConfig()
{
//新浪微博
__Dictionary *sinaConfigDict = __Dictionary::create();
sinaConfigDict -> setobject(String::create("568898243"),"app_key");
sinaConfigDict -> setobject(String::create("38a4f8204cc784f81f9f0daaf31e02e3"),"app_secret");
sinaConfigDict -> setobject(String::create("http://www.sharesdk.cn"),"redirect_uri");
C2DXShareSDK::setPlatformConfig(C2DXPlatTypeSinaWeibo,sinaConfigDict);
//QQ空间
__Dictionary *qzConfigDict = __Dictionary::create();
qzConfigDict -> setobject(String::create("100371282"),"app_ID");
qzConfigDict -> setobject(String::create("aed9b0303e3ed1e27bae87c33761161d"),"app_key");
C2DXShareSDK::setPlatformConfig(C2DXPlatTypeQZone,qzConfigDict);
//微信
__Dictionary *wcConfigDict = __Dictionary::create();
wcConfigDict -> setobject(String::create("wx4868b35061f87885"),"app_ID");
C2DXShareSDK::setPlatformConfig(C2DXPlatTypeWeixiSession,wcConfigDict);
C2DXShareSDK::setPlatformConfig(C2DXPlatTypeWeixiTimeline,wcConfigDict);
C2DXShareSDK::setPlatformConfig(C2DXPlatTypeWeixiFav,wcConfigDict);
__Dictionary *qqConfigDict = __Dictionary::create();
qqConfigDict -> setobject(String::create("100371282"),"app_ID");
C2DXShareSDK::setPlatformConfig(C2DXPlatTypeQQ,qqConfigDict);
}
HelloWorldScene.cpp
#include "C2DXShareSDK.h"
using namespace cn::sharesdk;
几个sharesdk回调方法:
voID authResultHandler(C2DXResponseState state,C2DXPlatType platType,__Dictionary *error)
{
switch (state) {
case C2DXResponseStateSuccess:
C2DXShareSDK::toast("授权成功");
break;
case C2DXResponseStateFail:
C2DXShareSDK::toast("授权失败");
break;
default:
C2DXShareSDK::toast("授权取消");
break;
}
}
voID getUserResultHandler(C2DXResponseState state,__Dictionary *userInfo,__Dictionary *error)
{
if (state == C2DXResponseStateSuccess)
{
//输出用户信息
__Array *allKeys = userInfo -> allKeys();
allKeys->retain();
for (int i = 0; i < allKeys -> count(); i++)
{
String *key = (String *)allKeys -> objectAtIndex(i);
Object *obj = userInfo -> objectForKey(key -> getCString());
cclog("key = %s",key -> getCString());
if (dynamic_cast<String *>(obj))
{
cclog("value = %s",dynamic_cast<String *>(obj) -> getCString());
}
else if (dynamic_cast<Integer *>(obj))
{
cclog("value = %d",dynamic_cast<Integer *>(obj) -> getValue());
}
else if (dynamic_cast<Double *>(obj))
{
cclog("value = %f",dynamic_cast<Double *>(obj) -> getValue());
}
}
allKeys->release();
}
}
voID shareResultHandler(C2DXResponseState state,__Dictionary *shareInfo,__Dictionary *error)
{
switch (state) {
case C2DXResponseStateSuccess:
C2DXShareSDK::toast("分享成功");
break;
case C2DXResponseStateFail:
C2DXShareSDK::toast("分享失败");
break;
default:
C2DXShareSDK::toast("分享取消");
break;
}
}
各种回调方法
voID authMenuItemClick(cocos2d::Ref* pSender);
voID cancelAuthMenuItemClick(cocos2d::Ref* pSender);
voID hasAuthMenuItemClick(cocos2d::Ref* pSender);
voID getUserInfoMenuItemClick(cocos2d::Ref* pSender);
voID shareMenuItemClick(cocos2d::Ref* pSender);
各种实现:
voID HelloWorld::authMenuItemClick(cocos2d::Ref* pSender)
{
C2DXShareSDK::authorize(C2DXPlatTypeFacebook,authResultHandler);
}
voID HelloWorld::cancelAuthMenuItemClick(cocos2d::Ref* pSender)
{
C2DXShareSDK::cancelAuthorize(C2DXPlatTypeSinaWeibo);
}
voID HelloWorld::hasAuthMenuItemClick(cocos2d::Ref* pSender)
{
if (C2DXShareSDK::hasautorized(C2DXPlatTypeSinaWeibo))
{
C2DXShareSDK::toast("用户已授权");
}
else
{
C2DXShareSDK::toast("用户尚未授权");
}
}
voID HelloWorld::getUserInfoMenuItemClick(cocos2d::Ref* pSender)
{
C2DXShareSDK::getUserInfo(C2DXPlatTypeSinaWeibo,getUserResultHandler);
}
voID HelloWorld::shareMenuItemClick(cocos2d::Ref* pSender)
{
__Dictionary *content = __Dictionary::create();
//Dictionary可用的Key如下,如果需要用到其它字段,可自行参考Sample中的代码实现:
// (并不是所有平台都有这些字段,需要参考文档http://wiki.mob.com/AndroID_%E4%B8%8D%E5%90%8C%E5%B9%B3%E5%8F%B0%E5%88%86%E4%BA%AB%E5%86%85%E5%AE%B9%E7%9A%84%E8%AF%A6%E7%BB%86%E8%AF%B4%E6%98%8E)
content -> setobject(String::create("这是一条测试内容"),"content"); //要分享的内容,注意在文档中content对应的是text字段
content -> setobject(String::create("http://img0.bdstatic.com/img/image/shouye/systsy-11927417755.jpg"),"image"); //可以是本地路径(如:/sdcard/a.jpg)或是一个URL
content -> setobject(String::create("测试标题"),"Title");
content -> setobject(String::create("测试描述"),"description");
content -> setobject(String::create("http://sharesdk.cn"),"url");
content -> setobject(String::createWithFormat("%d",C2DXContentTypeNews),"type");
content -> setobject(String::create("http://sharesdk.cn"),"siteUrl");
content -> setobject(String::create("ShareSDK"),"site");
content -> setobject(String::create("http://mp3.mwap8.com/destdir/Music/2009/20090601/ZuiXuanMinZuFeng20090601119.mp3"),"musicUrl");
content -> setobject(String::create("extInfo"),"extInfo"); //微信分享应用时传给应用的附加信息
C2DXShareSDK::showShareMenu(NulL,content,Vec2(100,100),C2DXMenuArrowDirectionleft,shareResultHandler);
// C2DXShareSDK::showShareVIEw(C2DXPlatTypeSinaWeibo,shareResultHandler);
}
--------------
初始化菜单
//---------------------ShareSDK 菜单开始
MenuItemLabel *authMenuItem = MenuItemLabel::create(LabelTTF::create("授权","Arial",40),
this,
menu_selector(HelloWorld::authMenuItemClick));
MenuItemLabel *cancelAuthMenuItem = MenuItemLabel::create(LabelTTF::create("取消授权",
this,
menu_selector(HelloWorld::cancelAuthMenuItemClick));
MenuItemLabel *hasAuthMenuItem = MenuItemLabel::create(LabelTTF::create("是否授权",
this,
menu_selector(HelloWorld::hasAuthMenuItemClick));
MenuItemLabel *getUserMenuItem = MenuItemLabel::create(LabelTTF::create("用户信息",
menu_selector(HelloWorld::getUserInfoMenuItemClick));
MenuItemLabel *shareMenuItem = MenuItemLabel::create(LabelTTF::create("分享",
menu_selector(HelloWorld::shareMenuItemClick));
Menu *itemsMenu = Menu::create(authMenuItem,cancelAuthMenuItem,hasAuthMenuItem,getUserMenuItem,shareMenuItem,(MenuItemLabel*)NulL);
itemsMenu -> alignItemsHorizontallyWithpadding(20);
itemsMenu -> setposition(ccp(Director::getInstance() -> getWinSize().wIDth / 2,100));
this -> addChild(itemsMenu);
//---------------------ShareSDK 菜单结束
----------------------------------------------
androID集成 ---注意 后台包名和key
1、导入proj.androID,并copy cocos2dx lib并将project.propertIEs的lib引用移除
2、配置简单的lib库
1-将androID的库改称 4.0.3,并将引用移除
2- 新建libs并将 sharesdk的lib包拷贝进去(下载定制的sharesdk lib包)
libs---mainlib里的libs拷贝进去,onekeyshare的libs
3、把ShareSDK的cocos2dx的sample项目里的res拷贝到项目中覆盖
4、修改AndroIDManifest.xml
1-添加activity到application
<activity
androID:name="cn.sharesdk.framework.ShareSDKUIShell"
androID:configChanges="keyboardHIDden|orIEntation|screenSize"
androID:theme="@androID:style/theme.Translucent.NoTitlebar"
androID:windowsoftinputMode="stateHIDden|adjustResize" >
<intent-filter>
<data androID:scheme="tencent100371282" />
<action androID:name="androID.intent.action.VIEW" />
<category androID:name="androID.intent.category.broWSABLE" />
<category androID:name="androID.intent.category.DEFAulT" />
</intent-filter>
</activity>
<!--微信分享回调 -->
<activity
androID:name=".wxAPI.WXEntryActivity"
androID:theme="@androID:style/theme.Translucent.NoTitlebar"
androID:configChanges="keyboardHIDden|orIEntation|screenSize"
androID:exported="true"
androID:screenorIEntation="portrait" />
2、添加权限
<uses-permission androID:name="androID.permission.GET_TASKS" />
<uses-permission androID:name="androID.permission.INTERNET" />
<uses-permission androID:name="androID.permission.ACCESS_WIFI_STATE" />
<uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE" />
<uses-permission androID:name="androID.permission.CHANGE_WIFI_STATE" />
<uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission androID:name="androID.permission.READ_PHONE_STATE" />
<uses-permission androID:name="androID.permission.MANAGE_ACCOUNTS" />
<uses-permission androID:name="androID.permission.GET_ACCOUNTS" />
3、 copy assets下的ShareSDK.xml 并做修改:
默认微信不能跳过审核,导致调不出来分享界面,
将BypassApproval设置为true
ID="3"
SortID="3"
AppID="wxa07ce7fdf0c98af0"
BypassApproval="true"
Enable="true" />
<WechatMoments
ID="4"
SortID="4"
AppID="wxa07ce7fdf0c98af0"
BypassApproval="true"
Enable="true" />
不懂的可以加我的QQ群: 239982941(cocos2d-x 3.x学习群)欢迎你的到来哦,看了博文给点脚印呗,谢谢啦~~
总结以上是内存溢出为你收集整理的cocos2d-x3.2中怎么做ShareSdk的步骤全部内容,希望文章能够帮你解决cocos2d-x3.2中怎么做ShareSdk的步骤所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)