下载SDK
1.1 登录官网
1.2 点击这里 下载SDK
1.3 勾选本人须要的平台,例如微信平台,而后本人写UI,只须要勾选 如下图:
点击保留配置之后,而后点击 下载 即可
导入SDK
将1.3步获取到的SDK,间接将整个SDK资源文件拖进我的项目里,如下图:
并且勾选以下3个选项
在点击Finish,实现导入。
增加依赖库
点击 “+” 号,并在弹框里输出以下依赖库,进行增加
必要依赖库:
libc++.tbd
libz.tbd
libsqlite3.tbd
配置-ObjC
在我的项目的Build Settings中的Other Linker Flags增加”-ObjC” ,留神大小写
配置ATS
在我的项目的info.plist中增加 App Transport Security Settings,类型为字典类型给它增加一个Key:Allow Arbitrary Loads,类型为Boolean类型,值为YES;
配置URL Scheme
关上我的项目Info选项,找到URL Types,增加微信的URL Scheme:初始化里的AppId就是URL SCheme,如下图:
配置白名单
在我的项目的info.plist中增加LSApplicationQueriesSchemes,类型为Array而后给它增加一个须要反对的我的项目,类型为字符串类型:微信白名单须要减少:wechat,weixin,weixinULAPI这3项,如下图:
留神:XCode13,iOS15上编译,白名单只读取前50个配置,前面配置的都会有效
配置Universal Link
Universal Link能够本人去生成,参考苹果官网文档,然而为了不便用户,节俭用户的工夫和精力,咱们也在后盾为客户生成了Universal Link,如下图:
Team id:开发者团队的ID,可在苹果开发者后盾查看
Bundle id:开发者账号下所有利用对应一个Bundle id,可见于我的项目plist文件中的Bundle identifier,务必与我的项目中保持一致
填写好这些信息保留之后,就能够将生成的Universal Link用于微信开放平台上,微信初始化里,我的项目里这3个中央进行配置
(1)微信里以 https://结尾,反斜杠结尾 这种模式填写如下:
(2)微信初始化里与微信开放平台一样模式以 https://结尾,反斜杠结尾 模式填写如下:
[platformsRegister setupWeChatWithAppId:@"wx617c77c82218ea2c" appSecret:@"c7253e5289986cf4c4c74d1ccc185fb1" universalLink:@"https://70imc.share2dlink.com/"];
(3)我的项目里以applinks:XXXX模式填写如下:增加Associated Domains(留神:证书必须开明这个性能哦)
而后双击Associated Domains
增加好点击 + 号,进行UL 配置,如下:
初始化SDK
在我的项目默认的plist文件里 配置ShareSDK的AppKey和AppSecret,键别离为 MOBAppKey 和 MOBAppSecret ,值为之前在MobTech官网开发者后盾申请的AppKey和AppSecret( 留神配置之后保留好,而后看我的项目的Info选项里有没有 )
初始化微信平台
我的项目启动的时候在 application:didFinishLaunchingWithOptions:中增加初始化第三方平台的办法
#import <ShareSDK/ShareSDK.h>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) { [platformsRegister setupWeChatWithAppId:@"wx617c77c82218ea2c" appSecret:@"c7253e5289986cf4c4c74d1ccc185fb1" universalLink:@"https://70imc.share2dlink.com/"]; }]; return YES;}
结构分享参数以及调用分享办法
可在本人须要登录的视图页面写一个分享按钮,而后在按钮事件里调用接口,代码如下:
#import <ShareSDK/ShareSDK.h>#import <ShareSDKUI/ShareSDK+SSUI.h>- (void)viewDidLoad { [super viewDidLoad];// Do any additional setup after loading the view. UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(80, 100, 280, 60); [button setTitle:@"分享" forState:UIControlStateNormal]; [button setBackgroundColor:[UIColor redColor]]; [button addTarget:**self** action:**@selector**(tag) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button];}-(void)tag{//结构分享参数NSMutableDictionary * params = [NSMutableDictionary dictionary];[params SSDKSetupShareParamsByText:@"test" images:@"http://download.sdk.mob.com/web/images/2019/07/30/14/1564468183056/750_750_65.12.png" url:[NSURL URLWithString:@"http://www.mob.com/"] title:@"title" type:SSDKContentTypeWebPage];//调用分享办法[ShareSDK share:SSDKPlatformTypeWechat parameters:params onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) { switch (state) { case SSDKResponseStateSuccess: NSLog(@"胜利");//胜利 break; case SSDKResponseStateFail: { NSLog(@"--%@",error.description); //失败 break; } case SSDKResponseStateCancel: //勾销 break; default: break; }}];}
受权登录
可在本人须要登录的视图页面写一个登录按钮,而后在按钮事件里调用接口,代码如下:
#import <ShareSDK/ShareSDK.h>- (void)viewDidLoad { [super viewDidLoad];// Do any additional setup after loading the view. UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(80, 100, 280, 60); [button setTitle:@"登录" forState:UIControlStateNormal]; [button setBackgroundColor:[UIColor redColor]]; [button addTarget:self action:@selector(tag) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button];}-(void)tag{ [ShareSDK authorize:SSDKPlatformTypeWechat settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) { switch (state) { case SSDKResponseStateSuccess: NSLog(@"%@",[user.credential rawData]); break; case SSDKResponseStateFail: { NSLog(@"--%@",error.description); //失败 break; } case SSDKResponseStateCancel: //用户勾销受权 break; default: break; }}];}}
如此,即可实现微信分享链接以及受权登录性能!