cocos2dx IOS微信分享

2021-07-09 16:30:17 字數 2933 閱讀 1363

c2dshareinstance.h c2dshareinstance.mm(.mm是用於c++與ios混編)是用於cocos2dx 與 ios 進行互動的,內部實現如下:

#ifndef c2dshareinstance_h

#define c2dshareinstance_h

#include "cocos2d.h"

class c2dxshareinstance

//建構函式是私有的

static c2dxshareinstance *m_pinstance;

public:

static c2dxshareinstance *getinstance();

//直接分享

void sharecontentclickhandler(std::string strlinkurl, std::string strlinktagname, std::string strlinktitle, std::string strlinkdescription, std::string strimage, int wxtype);

};

cd2shareinstance.cpp實現

//

// c2dshareinstance.m

// mygame

////

//#include "c2dshareinstance.h"

//winxin

#import "wxapimanager.h"

#import "wxapirequesthandler.h"

#import "respforwechatviewcontroller.h"

#import "constant.h"

c2dxshareinstance *c2dxshareinstance::m_pinstance = null;

c2dxshareinstance* c2dxshareinstance::getinstance()

return m_pinstance;

}void c2dxshareinstance::sharecontentclickhandler(std::string strlinkurl, std::string strlinktagname, std::string strlinktitle, std::string strlinkdescription, std::string strimage, int wxtype)

#import @inte***ce shareviewcontroller : uiviewcontroller

@end

@inte***ce shareviewcontroller()//@property (nonatomic) enum wxscene currentscene;

@end

@implementation shareviewcontroller

#pragma mark - view lifecycle

- (void)viewdidload

- (bool)shouldautorotatetointe***ceorientation:(uiinte***ceorientation)inte***ceorientation else

}- (void)dealloc

#pragma mark - wxapimanagerdelegate

- (void)managerdidrecvgetmessagereq:(getmessagefromwxreq *)req

- (void)managerdidrecvshowmessagereq:(showmessagefromwxreq *)req

- (void)managerdidrecvlaunchfromwxreq:(launchfromwxreq *)req

- (void)managerdidrecvmessageresponse:(sendmessagetowxresp *)response

- (void)managerdidrecvaddcardresponse:(addcardtowxcardpackageresp *)response

uialertview *alert = [[uialertview alloc] initwithtitle:@"add card resp"

message:cardstr

delegate:self

cancelbuttontitle:@"ok"

otherbuttontitles:nil, nil];

[alert show];

[alert release];

}- (void)managerdidrecvauthresponse:(sendauthresp *)response

@end

其中使用單例模式在呼叫的

sdk1.6.2加入你要實現分享的工程當中。

最後在要分享的地方新增**

#if(cc_target_platform == cc_platform_ios)

std::string strlinkurl = "";

std::string strlinkdescription = cutilex::getstring("room_shared");

std::string strimage = "icon-40.png";

c2dxshareinstance::getinstance()->sharecontentclickhandler(strlinkurl, "", strlinktitle, "", strimage,1);

#endif

demo是純ios,我們使用的時候,要把它剝離出來

cocos2d x IOS遊戲開發

捕魚達回顧 cocos2d x ios遊戲開發 捕魚達人1 內容介紹 上節回顧 cocos2d x ios遊戲開發 城市跑酷14 重寫觸屏 touch 事件處理機制,響應玩家操作 cclabelbmfont的特色就是以占用更多記憶體為代價加快標籤的更新,這與其他任何ccsprite類相似 在遊戲中使...

cocos2d x IOS遊戲開發

捕魚達回顧 cocos2d x ios遊戲開發 捕魚達人1 內容介紹 上節回顧 cocos2d x ios遊戲開發 城市跑酷3 讀取資源,設定背景層 遊戲的元素應該是多種多樣的,只有乙個背景就略顯單調了,這裡我們來加入一些道具。來看下具體的實現 加入背景 城市燈火 background ccspri...

cocos2d x ios遊戲開發初認識 一

用xcode新建工程,我用版本是xcode5開始執行會出現兩個錯誤,首先進行改錯。錯誤 clang error unknown argument websockets wunused command line argument hard error in future 只需將other link中 ...