189 8069 5689

ios开发与微信

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 *)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源码。


标题名称:ios开发与微信
转载来于:http://cdxtjz.cn/article/ghgjps.html

其他资讯