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 *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[WXApi registerApp:"wxd930ea5d5a258f4f"];
重写AppDelegate的handleOpenURL和openURL方法:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [WXApi handleOpenURL:url delegate:self];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [WXApi handleOpenURL:url delegate:self];
}
实现WXApiDelegate协议的两个方法:
- (void) onReq:(BaseReq*)req
- (void) onResp:(BaseResp*)resp
向微信发送图片的例子:
- (void) sendImageContent
{ WXMediaMessage *message = [WXMediaMessage message];
[message setThumbImage:[UIImage p_w_picpathNamed:"res2.jpg"]];
WXImageObject *ext = [WXImageObject object];
NSString *filePath = [[NSBundle mainBundle] pathForResource:"res2" ofType:@"jpg"];
ext.p_w_picpathData = [NSData dataWithContentsOfFile:filePath] ;
message.mediaObject = ext;
SendMessageToWXReq* req = [[[SendMessageToWXReq alloc] init]autorelease];
req.bText = NO;
req.message = message;
//req.scene = WXSceneTimeline; //选择发送到朋友圈,默认值为WXSceneSession,发送到会话
[WXApi sendReq:req];
}
收到微信程序回应的例子:
-(void) onResp:(BaseResp*)resp
{
if([resp isKindOfClass:[SendMessageToWXResp class]])
{
NSString *strMsg = [NSString stringWithFormat:"发送消息结果:d", resp.errCode];
...
}
OK!你已经能使用微信终端SDK的API内容了。如果想参考更多例子,请自行下载阅读微信SDK Sample Demo源码。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。