iOS 微信分享,iOS信分享

來源:互聯網
上載者:User

iOS 分享,iOS信分享

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.