}else if(s.find("CCNull")!=std::string::npos){
cJSON * json = cJSON_CreateNull();
return json;
}
CCLog("CCJSONConverter encountered an unrecognized type");
return NULL;
}
CCNumber和CCNull是ShareSDK组件自己实现的类名,这里无需修改。
接下来我们需要在AppDelegate.cpp中对ShareSDK做初始化了:
复制代码bool AppDelegate::applicationDidFinishLaunching() {
… …
initShareSDK();
… ..
}
void AppDelegate::initShareSDK()
{
// sina weibo
CCDictionary *sinaConfigDict = CCDictionary::create();
sinaConfigDict->setObject(CCString::create("YOUR_WEIBO_APPKEY"), "app_key");
sinaConfigDict->setObject(CCString::create("YOUR_WEBIO_APPSECRET"), "app_secret");
sinaConfigDict->setObject(CCString::create("http://www.easck.com/>
C2DXShareSDK::setPlatformConfig(C2DXPlatTypeSinaWeibo, sinaConfigDict);
// wechat
CCDictionary *wcConfigDict = CCDictionary::create();
wcConfigDict->setObject(CCString::create("YOUR_WECHAT_APPID"), "app_id");
C2DXShareSDK::setPlatformConfig(C2DXPlatTypeWeixiSession, wcConfigDict);
C2DXShareSDK::setPlatformConfig(C2DXPlatTypeWeixiTimeline, wcConfigDict);
C2DXShareSDK::setPlatformConfig(C2DXPlatTypeWeixiFav, wcConfigDict);
C2DXShareSDK::open(CCString::create("YOUR_SHARESDK_APPKEY"), false);
}
在Share按钮的事件回调函数中调用ShareSDK的接口进行社交平台分享:
复制代码void GameScene::menuShareCallback(Ref* sender)
{
Dictionary *content = Dictionary::create();
content->setObject(String::create("ShareSDK for Cocos2d-x 3.0rc2社交分享测试。")
, "content");










