ios开发与微信
http://open.weixin.qq.com/document/sdk/ios/index.html
微信终端SDK使用指南
向微信注册你的应用程序id。
下载微信终端SDK文件。
将SDK文件中包含的libWeChatSDK.a,WXApi.h, WXApiObject.h三个文件添加到你所建的工程中。
在Xcode4中,选择你的工程设置项,选中“TARGETS”一栏,在“info”标签栏的“URL type“添加“URL scheme”为你所注册的应用程序id。如果使用的是Xcode3或更低版本,则需要在plist文件中添加。
程序启动时,在代码中向微信终端注册你的id:
-(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{[WXApiregisterApp:"wxd930ea5d5a258f4f"];
重写AppDelegate的handleOpenURL和openURL方法:
-(BOOL)application:(UIApplication*)applicationhandleOpenURL:(NSURL*)url{return[WXApihandleOpenURL:urldelegate:self];}
-(BOOL)application:(UIApplication*)applicationopenURL:(NSURL*)urlsourceApplication:(NSString*)sourceApplicationannotation:(id)annotation{return[WXApihandleOpenURL:urldelegate:self];}
实现WXApiDelegate协议的两个方法:
-(void)onReq:(BaseReq*)req
-(void)onResp:(BaseResp*)resp
向微信发送图片的例子:
-(void)sendImageContent{WXMediaMessage*message=[WXMediaMessagemessage];[messagesetThumbImage:[UIImagep_w_picpathNamed:"res2.jpg"]];
WXImageObject*ext=[WXImageObjectobject];NSString*filePath=[[NSBundlemainBundle]pathForResource:"res2"ofType:@"jpg"];ext.p_w_picpathData=[NSDatadataWithContentsOfFile:filePath];
message.mediaObject=ext;
SendMessageToWXReq*req=[[[SendMessageToWXReqalloc]init]autorelease];req.bText=NO;req.message=message;//req.scene=WXSceneTimeline;//选择发送到朋友圈,默认值为WXSceneSession,发送到会话
[WXApisendReq:req];}
收到微信程序回应的例子:
-(void)onResp:(BaseResp*)resp{if([respisKindOfClass:[SendMessageToWXRespclass]]){NSString*strMsg=[NSStringstringWithFormat:"发送消息结果:d",resp.errCode];...}
OK!你已经能使用微信终端SDK的API内容了。如果想参考更多例子,请自行下载阅读微信SDK Sample Demo源码。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。