• Mob-第三方分享 /手机验证码


    介绍目录:

       1.第三方分享

       2.短信验证码

       3.使用时候常见的坑

       

    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.短信验证码,

     这个就要比分享要简单一点了

    首先  我们先创建几个控件

    1. // // 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卡。。。。。。

    3.在使用的时候常预见的坑   

     1.当我把shareSDK拖入到工程的时候,64个错误,检查了一下问题的原因,原来是BitCode设置出现了问题。

    2.IOS9之后,需要支持HTTPS协议做下改动

    3.进行SSO(免登录)和更多社交平台设置。



    4.在iOS 9下涉及到平台客户端跳转,系统会自动到项目info.plist下检测是否设置平台Scheme。对于需要配置的平台,如果没有配置,就无法正常跳转平台客户端。因此要支持客户端的分享和授权等,需要配置Scheme名单。 具体方法:


    1)、在项目的info.plist中添加一LSApplicationQueriesSchemes,类型为Array。

    2)、然后给它添加一个需要支持的项目,类型为字符串类型;

    5.修改分享平台信息

    踩过的雷,就要记得雷区的位置,万一可以再踩第二回呢?

  • 相关阅读:
    database backup scripts
    RMAN笔记之备份集和备份片
    数据缓冲区详解
    Oracle数据库中快照的使用
    linux 安装RabbitMQ 注意版本
    转 Oracle12c/11个 Client安装出现"[INS-30131]"错误“请确保当前用户具有访问临时位置所需的权限”解决办法之完整版
    Oracle alert日志中出现:‘Fatal NI connect error 12170’
    Oracle表分区分为四种:范围分区,散列分区,列表分区和复合分区
    python基础: String类型
    Python3 urllib模块的使用(转载)
  • 原文地址:https://www.cnblogs.com/Biaoac/p/5322960.html
Copyright © 2020-2023  润新知