sdk-ios
1.注册友盟
2.打开Docs->doc.html帮助文档
3.拖入工程中 create groups
4.把安卓平台相关删除 cocos2dx->Android、playform->Android、read….
5.添加下面的系统库
工程->Build Phases->Link Binary With Libraries +搜索添加
注:只需要搜索名字,不需要添加后缀名
Security.framework,libiconv.dylib,SystemConfiguration.framework,CoreGraphics.framework,libsqlite3.dylib,CoreTelephony.framework,libstdc++.dylib,libz.dylib,Social.framework,Accounts.framework。
6.头文件搜索问题 所以 设置搜索路径 Build Settings ->搜索框 搜索search
把Header Search Paths设置为根目录 $(PROJECT_DIR)/UMengSocialCocos2dx_5.0
继续添加库
following frameworks:
CoreData
CoreText
CoreGraphics
CoreTelephony
Foundation
QuartzCore
StoreKit
SystemConfiguration
UIKit
7.按需设置各个平台的URL Scheme
蓝色工程下的Info->URL Types
+ >winxin wxdc1e388c3822c80b
>alipayShare ap2015111700822536
> QQ05FC5B14
> sina.5211818556240bc9ee01db2f
> wb3921700954
> tencent100424468
> yx35664bdff4db42c2b7be1e29390c1a06
8.引入sdk头文件
#include "Cocos2dx/Common/CCUMSocialSDK.h"
#include "Cocos2dx/ShareButton/UMShareButton.h"
//使用友盟命名空间
USING_NS_UM_SOCIAL;
#define APPKEY "53290df956240b6b4a0084b3"
/*
* 分享回调, 该回调不是某个类的成员函数, 而是一个普通的函数, 具体使用参考HelloWorldScene的例子
* @param platform 要分享到的目标平台
* @param stCode 返回码, 200代表分享成功, 100代表开始分享
* @param errorMsg 分享失败时的错误信息,android平台没有错误信息
*/
void shareCallback(int platform, int stCode, string& errorMsg)
{
if ( stCode == 100 )
{
CCLOG("#### HelloWorld Start Share!");
}
else if ( stCode == 200 )
{
CCLOG("#### HelloWorld Share Succeed!");
}
else
{
CCLOG("#### HelloWorld Share Error!");
}
CCLOG("platform num is : %d.", platform);
}
// 创建分享按钮, 参数1为按钮正常情况下的图片, 参数2为按钮选中时的图片,参数3为友盟appkey, 参数4为分享回调
UMShareButton *shareButton = UMShareButton::create("CloseNormal.png","CloseSelected.png", APPKEY, share_selector(shareCallback)) ;
// 显示在友盟分享面板上的平台
vector<int>* platforms = new vector<int>();
platforms->push_back(SINA);
platforms->push_back(RENREN) ;
platforms->push_back(DOUBAN) ;
platforms->push_back(QZONE) ;
platforms->push_back(QQ) ;
// 设置友盟分享面板上显示的平台
shareButton->setPlatforms(platforms);
// 设置文本分享内容
shareButton->setShareContent("Hello youmeng!!.") ;
// 设置要分享的图片, 图片支持本地图片和url图片, 但是url图片必须以http://或者https://开头
shareButton->setShareImage("HelloWorld.png") ;
auto winSize = Director::getInstance()->getWinSize();
// 设置按钮的位置
shareButton->setPosition(winSize/2.0f);
// 然后开发者需要将该按钮添加到游戏场景中
Menu* pMenu = Menu::create(shareButton, NULL);
pMenu->setPosition(Vec2::ZERO);
this->addChild(pMenu, 1);
方式二
//conrtol控件 头文件
#include "cocos-ext.h"
USING_NS_CC_EXT;
//创建按钮
ControlButton* createButton(const char* normal, const char* selected, const char* disable, Ref* target, Control::Handler handle, bool isZoomOnTouchDown = true);
ControlButton* createButton(const char* normal, const char* selected, const char* disable, Ref* target, Control::Handler handle, bool isZoomOnTouchDown)
{
Scale9Sprite* sptNormal = Scale9Sprite::create(normal);
//先判断再赋值
Scale9Sprite* sptSelected = (selected == 0 ? 0 : Scale9Sprite::create(selected));
Scale9Sprite* sptDisable = disable == 0 ? 0 : Scale9Sprite::create(disable);
//关闭按钮
extension::ControlButton* bt = ControlButton::create(sptNormal);
//bt->setPreferredSize(sptNormal->getPreferredSize());
bt->setBackgroundSpriteForState(sptNormal, Control::State::NORMAL);
if (sptSelected)
bt->setBackgroundSpriteForState(sptSelected, Control::State::HIGH_LIGHTED);
if (sptDisable)
bt->setBackgroundSpriteForState(sptDisable, Control::State::DISABLED);
//触摸点击
bt->addTargetWithActionForControlEvents(target, handle, Control::EventType::TOUCH_UP_INSIDE);
bt->setZoomOnTouchDown(isZoomOnTouchDown);
return bt;
}
/*第二种方式*/
//qq
ControlButton* qq = createButton("res/freegold_share_qq.png", 0, 0, this, cccontrol_selector(HelloWorld::callBack));
qq->setTag(shareStyle::qq);
qq->setPosition(winSize.width/2,winSize.height-20);
this->addChild(qq);
//qqzone
ControlButton* qzone = createButton("res/freegold_share_qzone.png", 0, 0, this, cccontrol_selector(HelloWorld::callBack));
qzone->setTag(shareStyle::qzone);
qzone->setPosition(winSize.width/2,winSize.height-80);
this->addChild(qzone);
//sina
ControlButton* sina = createButton("res/freegold_share_sina.png", 0, 0, this, cccontrol_selector(HelloWorld::callBack));
sina->setTag(shareStyle::sina);
sina->setPosition(winSize.width/2,winSize.height-140);
this->addChild(sina);
//weixin
ControlButton* weixin = createButton("res/freegold_share_weixin.png", 0, 0, this, cccontrol_selector(HelloWorld::callBack));
weixin->setTag(shareStyle::weixin);
weixin->setPosition(winSize.width/2,winSize.height-200);
this->addChild(weixin);
//weixinCircle
ControlButton*weixinCircle = createButton("res/freegold_share_weixin_circle.png", 0, 0, this, cccontrol_selector(HelloWorld::callBack));
weixinCircle->setTag(shareStyle::weixinCircle);
weixinCircle->setPosition(winSize.width/2,winSize.height-260);
this->addChild(weixinCircle);
//创建按钮时所需要的参数之一
void HelloWorld::callBack(Ref* ref,Control::EventType type){
ControlButton* btn = dynamic_cast<ControlButton*>(ref);
int tag = btn->getTag();
//
CCUMSocialSDK* sdk = CCUMSocialSDK::create(APPKEY);
sdk->setTargetUrl("www.baidu.com");
switch(tag){
case shareStyle::qq:
sdk->setQQAppIdAndAppKey("100424468", "c7394704798a158208a74ab60104f0ba");
//授权 授权平台 授权函数
sdk->authorize(QQ, auth_selector(authCallback));
sdk->directShare(QQ, "hello", "HelloWorld.png", share_selector(shareCallback));
break;
case shareStyle::qzone:
sdk->setQQAppIdAndAppKey("100424468", "c7394704798a158208a74ab60104f0ba");
//授权 授权平台 授权函数
sdk->authorize(QQ, auth_selector(authCallback));
sdk->directShare(QZONE, "hello", "HelloWorld.png", share_selector(shareCallback));
break;
//新浪
case shareStyle::sina:
sdk->setSinaAppKey("3921700954", "04b48b094faeb16683c32669824ebdad", "http://sns.whalecloud.com/sina2/callback");
sdk->directShare(SINA, "hello sina", "HelloWorld.png", share_selector(shareCallback));
break;
case shareStyle::weixin:
sdk->setWeiXinAppInfo("wx485ab7ca6a7e02d1", "f9cad1d153aaa97925a2e2b5fa63d59f");
sdk->directShare(WEIXIN, "hello weixin", "HelloWorld.png", share_selector(shareCallback));
break;
case shareStyle::weixinCircle:
sdk->setWeiXinAppInfo("wx485ab7ca6a7e02d1", "f9cad1d153aaa97925a2e2b5fa63d59f");
sdk->directShare(WEIXIN_CIRCLE, "hello weixin", "HelloWorld.png", share_selector(shareCallback));
break;
case shareStyle::weibo:
break;
default:
break;
}
}
CocoaLigature1
1.注册友盟
2.打开Docs->doc.html帮助文档
3.拖入工程中 create groups
4.把安卓平台相关删除 cocos2dx->Android、playform->Android、read….
5.添加下面的系统库
工程->Build Phases->Link Binary With Libraries +搜索添加
注:只需要搜索名字,不需要添加后缀名
Security.framework,libiconv.dylib,SystemConfiguration.framework,CoreGraphics.framework,libsqlite3.dylib,CoreTelephony.framework,libstdc++.dylib,libz.dylib,Social.framework,Accounts.framework。
6.头文件搜索问题 所以 设置搜索路径 Build Settings ->搜索框 搜索search
把Header Search Paths设置为根目录 $(PROJECT_DIR)/UMengSocialCocos2dx_5.0
继续添加库
following frameworks:
CoreData
CoreText
CoreGraphics
CoreTelephony
Foundation
QuartzCore
StoreKit
SystemConfiguration
UIKit
7.按需设置各个平台的URL Scheme
蓝色工程下的Info->URL Types
+ >winxin wxdc1e388c3822c80b
>alipayShare ap2015111700822536
> QQ05FC5B14
> sina.5211818556240bc9ee01db2f
> wb3921700954
> tencent100424468
> yx35664bdff4db42c2b7be1e29390c1a06
8.引入sdk头文件
#include "Cocos2dx/Common/CCUMSocialSDK.h"
#include "Cocos2dx/ShareButton/UMShareButton.h"
//使用友盟命名空间
USING_NS_UM_SOCIAL;
#define APPKEY "53290df956240b6b4a0084b3"
/*
* 分享回调, 该回调不是某个类的成员函数, 而是一个普通的函数, 具体使用参考HelloWorldScene的例子
* @param platform 要分享到的目标平台
* @param stCode 返回码, 200代表分享成功, 100代表开始分享
* @param errorMsg 分享失败时的错误信息,android平台没有错误信息
*/
void shareCallback(int platform, int stCode, string& errorMsg)
{
if ( stCode == 100 )
{
CCLOG("#### HelloWorld Start Share!");
}
else if ( stCode == 200 )
{
CCLOG("#### HelloWorld Share Succeed!");
}
else
{
CCLOG("#### HelloWorld Share Error!");
}
CCLOG("platform num is : %d.", platform);
}
// 创建分享按钮, 参数1为按钮正常情况下的图片, 参数2为按钮选中时的图片,参数3为友盟appkey, 参数4为分享回调
UMShareButton *shareButton = UMShareButton::create("CloseNormal.png","CloseSelected.png", APPKEY, share_selector(shareCallback)) ;
// 显示在友盟分享面板上的平台
vector<int>* platforms = new vector<int>();
platforms->push_back(SINA);
platforms->push_back(RENREN) ;
platforms->push_back(DOUBAN) ;
platforms->push_back(QZONE) ;
platforms->push_back(QQ) ;
// 设置友盟分享面板上显示的平台
shareButton->setPlatforms(platforms);
// 设置文本分享内容
shareButton->setShareContent("Hello youmeng!!.") ;
// 设置要分享的图片, 图片支持本地图片和url图片, 但是url图片必须以http://或者https://开头
shareButton->setShareImage("HelloWorld.png") ;
auto winSize = Director::getInstance()->getWinSize();
// 设置按钮的位置
shareButton->setPosition(winSize/2.0f);
// 然后开发者需要将该按钮添加到游戏场景中
Menu* pMenu = Menu::create(shareButton, NULL);
pMenu->setPosition(Vec2::ZERO);
this->addChild(pMenu, 1);
方式二
//conrtol控件 头文件
#include "cocos-ext.h"
USING_NS_CC_EXT;
//创建按钮
ControlButton* createButton(const char* normal, const char* selected, const char* disable, Ref* target, Control::Handler handle, bool isZoomOnTouchDown = true);
ControlButton* createButton(const char* normal, const char* selected, const char* disable, Ref* target, Control::Handler handle, bool isZoomOnTouchDown)
{
Scale9Sprite* sptNormal = Scale9Sprite::create(normal);
//先判断再赋值
Scale9Sprite* sptSelected = (selected == 0 ? 0 : Scale9Sprite::create(selected));
Scale9Sprite* sptDisable = disable == 0 ? 0 : Scale9Sprite::create(disable);
//关闭按钮
extension::ControlButton* bt = ControlButton::create(sptNormal);
//bt->setPreferredSize(sptNormal->getPreferredSize());
bt->setBackgroundSpriteForState(sptNormal, Control::State::NORMAL);
if (sptSelected)
bt->setBackgroundSpriteForState(sptSelected, Control::State::HIGH_LIGHTED);
if (sptDisable)
bt->setBackgroundSpriteForState(sptDisable, Control::State::DISABLED);
//触摸点击
bt->addTargetWithActionForControlEvents(target, handle, Control::EventType::TOUCH_UP_INSIDE);
bt->setZoomOnTouchDown(isZoomOnTouchDown);
return bt;
}
/*第二种方式*/
ControlButton* qq = createButton("res/freegold_share_qq.png", 0, 0, this, cccontrol_selector(HelloWorld::callBack));
qq->setTag(shareStyle::qq);
qq->setPosition(winSize.width/2,winSize.height-20);
this->addChild(qq);
//qqzone
ControlButton* qzone = createButton("res/freegold_share_qzone.png", 0, 0, this, cccontrol_selector(HelloWorld::callBack));
qzone->setTag(shareStyle::qzone);
qzone->setPosition(winSize.width/2,winSize.height-80);
this->addChild(qzone);
//sina
ControlButton* sina = createButton("res/freegold_share_sina.png", 0, 0, this, cccontrol_selector(HelloWorld::callBack));
sina->setTag(shareStyle::sina);
sina->setPosition(winSize.width/2,winSize.height-140);
this->addChild(sina);
//weixin
ControlButton* weixin = createButton("res/freegold_share_weixin.png", 0, 0, this, cccontrol_selector(HelloWorld::callBack));
weixin->setTag(shareStyle::weixin);
weixin->setPosition(winSize.width/2,winSize.height-200);
this->addChild(weixin);
//weixinCircle
ControlButton*weixinCircle = createButton("res/freegold_share_weixin_circle.png", 0, 0, this, cccontrol_selector(HelloWorld::callBack));
weixinCircle->setTag(shareStyle::weixinCircle);
weixinCircle->setPosition(winSize.width/2,winSize.height-260);
this->addChild(weixinCircle);
//创建按钮时所需要的参数之一
void HelloWorld::callBack(Ref* ref,Control::EventType type){
ControlButton* btn = dynamic_cast<ControlButton*>(ref);
int tag = btn->getTag();
//
CCUMSocialSDK* sdk = CCUMSocialSDK::create(APPKEY);
sdk->setTargetUrl("www.baidu.com");
switch(tag){
case shareStyle::qq:
sdk->setQQAppIdAndAppKey("100424468", "c7394704798a158208a74ab60104f0ba");
//授权 授权平台 授权函数
sdk->authorize(QQ, auth_selector(authCallback));
sdk->directShare(QQ, "hello", "HelloWorld.png", share_selector(shareCallback));
break;
case shareStyle::qzone:
sdk->setQQAppIdAndAppKey("100424468", "c7394704798a158208a74ab60104f0ba");
//授权 授权平台 授权函数
sdk->authorize(QQ, auth_selector(authCallback));
sdk->directShare(QZONE, "hello", "HelloWorld.png", share_selector(shareCallback));
break;
//新浪
case shareStyle::sina:
sdk->setSinaAppKey("3921700954", "04b48b094faeb16683c32669824ebdad", "http://sns.whalecloud.com/sina2/callback");
sdk->directShare(SINA, "hello sina", "HelloWorld.png", share_selector(shareCallback));
break;
case shareStyle::weixin:
sdk->setWeiXinAppInfo("wx485ab7ca6a7e02d1", "f9cad1d153aaa97925a2e2b5fa63d59f");
sdk->directShare(WEIXIN, "hello weixin", "HelloWorld.png", share_selector(shareCallback));
break;
case shareStyle::weixinCircle:
sdk->setWeiXinAppInfo("wx485ab7ca6a7e02d1", "f9cad1d153aaa97925a2e2b5fa63d59f");
sdk->directShare(WEIXIN_CIRCLE, "hello weixin", "HelloWorld.png", share_selector(shareCallback));
break;
case shareStyle::weibo:
break;
default:
break;
}
}
CocoaLigature1