标签:
介绍目录:
1.第三方分享
2.短信验证码
1.第三方分享
其实,现在有很多的第三方分享的工具,今天给大家介绍一个比较好用的分享工具
Mob-第三方分享
1.下载SDKhttp://sharesdk.mob.com/#/downloadDetail/ShareSDK/ios
2.导入下载好的框架到工程
3.获取AppKey(第三方框架的APPKey)
4.添加依赖库
(1)全部都必须添加的
libicucore.dylib
libz.dylib
libstdc++.dylib
JavaScriptCore.framework
(2)新浪微博SDK依赖库
ImageIO.framework
libsqlite3.dylib
(3)QQ好友和QQ空间SDK依赖库
libsqlite3.dylib
(4)微信SDK依赖库
libsqlite3.dylib
(5)短信和邮件需要依赖库
MessageUI.framework
5.在target-userInfo-搜索BitCode将BitCode设置为NO
6.在info->URL Types ->添加URL Schemes->申请微信 QQ 微博... 的appKey
7.在info.plist中添加LSApplicationQueriesSchemes数组->添加需要添加的分享方如(weixin)
8.info.plist->App Transport Security Settings->Allow Arbitrary Loads为YES
9.初始化对应的第三方社交平台
10.示例代码
// // ViewController.m // ShareSDK分享 // // Created by Bruce on 16/3/23. // Copyright © 2016年 Bruce. All rights reserved. // #import "ViewController.h" #import <ShareSDK/ShareSDK.h> #import <ShareSDKConnector/ShareSDKConnector.h> #import <TencentOpenAPI/TencentOAuth.h> #import <TencentOpenAPI/QQApiInterface.h> #import "WXApi.h" #import "WeiboSDK.h" #import <ShareSDKUI/ShareSDKUI.h> @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(100, 100, 100, 100); [button setTitle:@"TICK" forState:UIControlStateNormal]; button.backgroundColor = [UIColor brownColor]; [button addTarget:self action:@selector(share) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } - (void)shareToMessage{ } - (void)share{ /** * 设置ShareSDK的appKey,如果尚未在ShareSDK官网注册过App,请移步到http://mob.com/login 登录后台进行应用注册 * 在将生成的AppKey传入到此方法中。 * 方法中的第二个第三个参数为需要连接社交平台SDK时触发, * 在此事件中写入连接代码。第四个参数则为配置本地社交平台时触发,根据返回的平台类型来配置平台信息。 * 如果您使用的时服务端托管平台信息时,第二、四项参数可以传入nil,第三项参数则根据服务端托管平台来决定要连接的社交SDK。 */ [ShareSDK registerApp:@"9111ac801dfd" activePlatforms:@[ @(SSDKPlatformTypeWechat)] onImport:^(SSDKPlatformType platformType) { switch (platformType) { case SSDKPlatformTypeWechat: [ShareSDKConnector connectWeChat:[WXApi class]]; break; default: break; } } onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) { switch (platformType) { case SSDKPlatformTypeWechat: [appInfo SSDKSetupWeChatByAppId:@"wx72b5127c27ac3f37" appSecret:@"affa7858a98a36bfddfb57f8a1f753ad"]; break; default: break; } }]; //1、创建分享参数 NSArray* imageArray = @[[UIImage imageNamed:@"res2.jpg"]]; // (注意:图片必须要在Xcode左边目录里面,名称必须要传正确,如果要分享网络图片,可以这样传iamge参数 images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"]) if (imageArray) { NSMutableDictionary *shareParams = [NSMutableDictionary dictionary]; [shareParams SSDKSetupShareParamsByText:@"测试分享的内容" images:imageArray url:[NSURL URLWithString:@"http://mob.com"] title:@"测试标题" type:SSDKContentTypeAuto]; //2、分享(可以弹出我们的分享菜单和编辑界面) [ShareSDK showShareActionSheet:nil //要显示菜单的视图, iPad版中此参数作为弹出菜单的参照视图,只有传这个才可以弹出我们的分享菜单,可以传分享的按钮对象或者自己创建小的view 对象,iPhone可以传nil不会影响 items:nil shareParams:shareParams onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) { switch (state) { case SSDKResponseStateSuccess: { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alertView show]; break; } case SSDKResponseStateFail: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败" message:[NSString stringWithFormat:@"%@",error] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; NSLog(@">>>>>>:%@",error); break; } default: break; } } ]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
注意:1. 如果你的分享不成功,请检查你的前几步配置设置好;;;;
2。用真机才能运行,因为你的模拟器上面可没有微信,也没有qq,
2.短信验证码,
这个就要比分享要简单一点了
首先 我们先创建几个控件
// // ViewController.h // Mob短信验证 // // Created by Bruce on 16/3/25. // Copyright © 2016年 Bruce. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (strong, nonatomic) IBOutlet UITextField *codeTextField; - (IBAction)send:(id)sender; - (IBAction)done:(id)sender; - (IBAction)hiddenKeyBoard:(id)sender; @end
下面是实现文件:
// // ViewController.m // Mob短信验证 // // Created by Bruce on 16/3/25. // Copyright © 2016年 Bruce. All rights reserved. // #import "ViewController.h" #import <SMS_SDK/SMSSDK.h> @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)send:(id)sender { [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:@"13370116152" zone:@"86" customIdentifier:nil result:^(NSError *error) { NSLog(@"%@",error); }]; } - (IBAction)done:(id)sender { [SMSSDK commitVerificationCode:self.codeTextField.text phoneNumber:@"13370116152" zone:@"86" result:^(NSError *error) { if (!error) { NSLog(@"验证成功"); } else { NSLog(@"错误信息:%@",error); } }]; } - (IBAction)hiddenKeyBoard:(id)sender { [self.codeTextField resignFirstResponder]; } @end
注意,必须是真机的情况下,模拟器可没有SIM卡。。。。。。
标签:
原文地址:http://www.cnblogs.com/Biaoac/p/5322960.html