1.注册微信开放平台账号:https://open.weixin.qq.com
images/loading.gif' data-original="http://images2015.cnblogs.com/blog/800567/201512/800567-20151224143525452-1538129355.png" width="653" height="452" />
2.创建应用
设置图片可以使用一个小工具,详情http://www.cnblogs.com/czq1989/p/5073586.html
一般审核几个小时就过了,审核通过之后也能删除掉这个应用
3.下载微信SDK
4.搭建开发环境
导入开发包中的文件
导入依赖库,官方说要导入四个
SystemConfiguration.framework
libz.tbd
libsqlite3.0.tbd
libc++.tbd
配置url type
5.写入相关代码
AppDelegate.m中
注意一点,重写的那两个方法现在不用了,适配一下低版本就可以了
导入WXApi.h
1 #import "WXApi.h"
遵守WXApiDelegate协议
1 @interface AppDelegate ()<WXApiDelegate>
在didFinishLaunchingWithOptions方法中进行App注册
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [WXApi registerApp:@"################"]; return YES;}
重写appdelegate的两个方法
1 - (BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url {2 return [WXApi handleOpenURL:url delegate:self];3 }
1 - (BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {2 return [WXApi handleOpenURL:url delegate:self];3 }
在ViewController.m里我们创建一个button,点击完成分享
1 #import "ViewController.h" 2 #import "WXApi.h" 3 4 @interface ViewController ()<WXApiDelegate> 5 6 @end 7 8 @implementation ViewController 9 10 - (void)viewDidLoad {11 [super viewDidLoad];12 [self setButton];13 // Do any additional setup after loading the view, typically from a nib.14 }15 16 - (void)setButton {17 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];18 [button setFrame:CGRectMake(120, 120, 120, 36)];19 [button setTitle:@"SharingTest" forState:UIControlStateNormal];20 [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];21 [self.view addSubview:button];22 [button addTarget:self action:@selector(sendMessage) forControlEvents:UIControlEventTouchUpInside];23 }24 25 - (void)sendMessage {26 SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];27 req.text = @"TigerCui的测试消息,请忽略";28 req.bText = YES;29 req.scene = WXSceneSession;30 [WXApi sendReq:req];31 }
6.中间遇到的小问题
demo:https://github.com/TigerCui/WeChatSharingDemo.git
原标题:iOS 微信分享
关键词:IOS