1.注冊微信開放平台賬號:https://open.weixin.qq.com
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