void HomeSceneLayer::menuShareCallback(cocos2d::Ref* pSender){ #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // 获取一个CCUMSocialSDK实例 CCUMSocialSDK *sdk = CCUMSocialSDK::create("5568516967e58e897a0011b9"); // 设置友盟appkey,如果create中设置了不用调用该函数 // sdk->setAppKey("4eaee02c527015373b000003"); // ********************** 设置平台信息 *************************** sdk->setQQAppIdAndAppKey("1104678982", "7L3gWJ8PaTha6JMb"); sdk->setWeiXinAppInfo("wx44a50d1bd0fe1bb8","b5e2dd02b8417337c6ac324d90a9e276"); // sdk->setYiXinAppKey("设置易信和易信朋友圈的app id"); // sdk->setLaiwangAppInfo("设置来往和来往动态的app id", // "设置来往和来往动态的app key", "我的应用名"); // sdk->setFacebookAppId("你的facebook appid"); // // 打开或者关闭log sdk->setLogEnable(true) ; // ********************** END *************************** // 设置用户点击一条图文分享时用户跳转到的目标页面, 一般为app主页或者下载页面 sdk->setTargetUrl("http://keng.mm88bb.com/"); // 设置友盟分享面板上显示的平台 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) ;//也不需要QQ的 platforms->push_back(WEIXIN_CIRCLE) ; //添加朋友圈 // 设置平台, 在调用分享、授权相关的函数前必须设置SDK支持的平台 sdk->setPlatforms(platforms) ; // 打开分享面板, 注册分享回调, 参数1为分享面板上的平台, 参数2为要分享的文字内容, // 参数3为要分享的图片路径(android和IOS的图片地址格式不一致,因此分平台设置), 参数4为分享回调. auto ret=UserDefault::getInstance()->getStringForKey("string"); __String *str2=__String::createWithFormat("#保卫小和尚#本人最高得分%d分。做事要掌握好节奏,否则会死",Value(ret.c_str()).asInt()); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) sdk->openShare("#保卫小和尚#本人最高得分120分,获得过", "assets/ic_lunch_share.png", NULL); //设置微信分享内容 sdk->setPlatformShareContent(WEIXIN_CIRCLE, "weixin-share", "assets/ic_lunch_share.png", str2->getCString(), "http://blog.csdn.net/bboyfeiyu"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) sdk->openShare("要分享的文字内容","share.png",NULL); #endif #endif//以上代码是安卓引用文件 }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if (!CCLayer::init()) { return false; } // ******************** 设置友盟的app key以及相关的信息 *********************************** // 获取CCUMSocialSDK对象, 如果使用的UMShareButton, 则通过UMShareButton对象的getSocialSDK()方法获取. CCUMSocialSDK *sdk = CCUMSocialSDK::create("4eaee02c527015373b000003"); sdk->setTargetUrl("http://www.umeng.com/social"); // // 设置友盟app key // sdk->setAppKey("507fcab25270157b37000010"); sdk->setQQAppIdAndAppKey("100424468", "c7394704798a158208a74ab60104f0ba"); sdk->setWeiXinAppId("wx485ab7ca6a7e02d1"); sdk->setYiXinAppKey("yx52dd5c14bbb3430b93e6f2dafcbcc68d"); sdk->setLaiwangAppInfo("设置来往和来往动态的app id", "设置来往和来往动态的app key", "我的应用名"); sdk->setFacebookAppId("567261760019884"); sdk->openTwitterForiOS(); // 设置用户点击一条图文分享时用户跳转到的目标页面, 一般为app主页或者下载页面 CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); // 打开分享面板 CCMenuItemFont *shareTextButton = CCMenuItemFont::create("打开分享面板", this, menu_selector(HelloWorld::menuShareCallback)); shareTextButton->setPosition(ccp(150, 480)); // 底层API分享 CCMenuItemFont *directTextButton = CCMenuItemFont::create("底层分享", this, menu_selector(HelloWorld::directShareCallback)); directTextButton->setPosition(ccp(150, 400)); // 授权某平台 CCMenuItemFont *authTextButton = CCMenuItemFont::create("授权某平台", this, menu_selector(HelloWorld::authorizeCallback)); authTextButton->setPosition(ccp(150, 320)); // 删除某平台授权 CCMenuItemFont *delAuthTextButton = CCMenuItemFont::create("删除某平台删除", this, menu_selector(HelloWorld::deleteAuthorizeCallback)); delAuthTextButton->setPosition(ccp(150, 240)); // 判断某平台是否授权 CCMenuItemFont *isAuthTextButton = CCMenuItemFont::create("判断某平台是否授权", this, menu_selector(HelloWorld::isAuthorizedShareCallback)); isAuthTextButton->setPosition(ccp(150, 160)); // ******************************************************************************** // 打开或者关闭log sdk->setLogEnable(true); // 关闭按钮 CCMenuItemImage *pCloseItem = CCMenuItemImage::create("CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition( ccp( origin.x + visibleSize.width - pCloseItem->getContentSize().width / 2, origin.y + pCloseItem->getContentSize().height / 2)); // 友盟share button, 参数1为正常情况下的图片, 参数2为用户点击后的图片, 参数3为友盟app key, 参数四为分享回调. UMShareButton *shareButton = UMShareButton::create("share.png", "CloseSelected.png", "4eaee02c527015373b000003", share_selector(shareCallback)); vector<int>* platforms = new vector<int>(); platforms->push_back(SINA); platforms->push_back(FACEBOOK); // platforms->push_back(INSTAGRAM); platforms->push_back(QZONE); platforms->push_back(QQ); platforms->push_back(YIXIN_CIRCLE); platforms->push_back(YIXIN); platforms->push_back(WEIXIN); shareButton->setPlatforms(platforms) ; shareButton->setShareContent("这是很长的文字内容是个撒刚好是法国是大家给老师发给了对方两个"); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) shareButton->setShareImage(NULL); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) shareButton->setShareImage("share.png"); #endif // 设置分享回调 shareButton->setShareCallback(share_selector(shareCallback)); shareButton->setPosition(ccp(480, 150)); CCMenuItemFont *umshareTextButton = CCMenuItemFont::create("友盟ShareButton"); umshareTextButton->setPosition(ccp(480, 60)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(); pMenu->addChild(pCloseItem, 1); // 友盟share button pMenu->addChild(shareButton, 1); pMenu->addChild(umshareTextButton, 1); // 文字按钮 pMenu->addChild(shareTextButton, 1); pMenu->addChild(directTextButton, 1); pMenu->addChild(authTextButton, 1); pMenu->addChild(delAuthTextButton, 1); pMenu->addChild(isAuthTextButton, 1); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label CCLabelTTF* pLabel = CCLabelTTF::create("Umeng Social Cocos2d-x SDK", "Arial", 34); pLabel->setTag(labelTag); // position the label on the center of the screen pLabel->setPosition( ccp(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen pSprite->setPosition( ccp(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); return true; }