1. 在微信开放平台中创建你应用
首先需要在微信开放平台中注册你的应用,取得微信给你的AppID。在分享的过程中,我们需要使用这个AppID。具体的注册步骤跟着微信的平台一步步走就好。审核的过程大概需要2-3天。审核通过后如下可以看到:
微信审核页面2. 在你的应用中进行如下的操作
- 第一:在你的应用中:
TARGETS -> Build Phases -> Link Binary With Libraries
添加如下的框架- 点击下方的 "+" 添加:
libc++.tbd CoreTelephony.framework SystemConfiguration.framework libWeChatSDK.a
- 点击下方的 "+" ,然后点击
Add Other...
,按住cmd + Shift + G
, 输入/usr/lib
,点击Go
搜索下面的两个库进行添加。
libz.1.dylib libsqlite3.dylib
- 第二:在你的
AppDelegate.m
文件中- 导入文件:
#import "WXApi.h"
- 在下面的函数中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
输入如下内容
// 注册微信Api [WXApi registerApp:@"wx1234567890"]; //将这里的wx1234567890用你申请到的AppleID替换
- 导入文件:
- 第三:用微信的官方文档发送请求就好。
咳咳。为了方便使用,我自己进行了一个简单的二次封装,大家也可以直接拿来使用。
3. 使用封装好的文件到底有多简单!
觉得好用,来个赞好不好...
- 第一:在BYRWechatShare页面中,下载
BYRWechatShare.h; BYRWechatShare.m
这两个文件,拖拽到你的Project当中; - 第二:在你需要使用分享的
ViewController
当中,先引入
#import "BYRWechatShare.h"
。
下面是使用的例子- 分享文字
在文件中调用:/** * 分享文字 * content: 需要分享的文字内容 * type: 0:分享给微信好友;1:分享到朋友圈 **/ + (void)shareToWechatWithText:(NSString *)content type:(NSUInteger)type;
[BYRWechatShare shareToWechatWithText:@"LeeLom大帅比 哈哈" type:0];
- 分享图片
/**
* 分享图片
* image: 需要分享的图片
* thumbImage: 缩略图
* type: 0:分享给微信好友;1:分享到朋友圈
**/
+ (void)shareToWechatWithImage:(UIImage *)image
thumbImage:(UIImage *)thumbImage
type:(NSUInteger)type;
调用的例子
// image 和 thumbImage可以不一样
UIImage *image = [UIImage imageNamed:@"test"];
UIImage *thumbImage = [UIImage imageNamed:@"test"];
[BYRWechatShare shareToWechatWithImage:image thumbImage:thumbImage type:0];
tupian.jpeg
- 分享音乐
/**
* 分享音乐
* title: 音乐标题
* description: 音乐描述
* thumbImage: 缩略图
* musicUrl: 音乐url
* musicDataUrl: 音乐数据url
* type: 0:分享给微信好友;1:分享到朋友圈
**/
+ (void)shareToWechatWithMusicTitle:(NSString *)title
description:(NSString *)description
thumbImage:(UIImage *)thumbImage
musicUrl:(NSString *)musicUrl
musicDataUrl:(NSString *)musicDataUrl
type:(NSUInteger)type;
调用的例子
UIImage *thumbImage = [UIImage imageNamed:@"test"];
[BYRWechatShare shareToWechatWithMusicTitle:@"歌曲名"
description:@"歌曲描述"
thumbImage:thumbImage
musicUrl:@"www.baidu.com" //替换你的URL
musicDataUrl:@"www.baidu.com" //替换你的URL
type:1];
歌曲.jpeg
- 分享网页
/**
* 分享网页
* title: 网页标题
* description: 网页描述
* thumbImage: 缩略图
* webpageUrl: 网页url
* type: 0:分享给微信好友;1:分享到朋友圈
**/
+ (void)shareToWechatWithWebTitle:(NSString *)title
description:(NSString *)description
thumbImage:(UIImage *)thumbImage
webpageUrl:(NSString *)webpageUrl
type:(NSUInteger)type;
[BYRWechatShare shareToWechatWithWebTitle:@"网页名字"
description:@"网页描述"
thumbImage:thumbImage
webpageUrl:@"www.baidu.com"
type:1];
wangyemingzi.jpeg
网友评论