原生接入,Runtime技能科学商讨

乐播投屏SDK下载

原稿网站:http://www.jianshu.com/p/7e3c5fc31708

#import "MainTableViewController.h"

一、充实新本事篇**

在Build Setting中Other Linker Flags添加-ObjC

0.demo说明
其他先不说demo地址如下
1.demo下载下来将来,请在WTThirdPartyLoginManager里面将自个儿的个阳台的app key写上去.
2.U智跑L Schemes 也请各位自身布置好
demo地址
资料筹划
率先我们必要调味品有 (点击链接下载~)
今日头条天涯论坛sdk
腾讯sdk
微信sdk

#import "MJRefresh.h"

TridonLee要透过Category和Associated Objects扩展技术了,快看!

Bulid Phases加多系统类库

微信登陆官方文书档案

#import "HUDViewController.h"

创制TLPeople Associated.h文件如下:

图片 1

今日头条得到客户消息接口连接1
博客园得到顾客音信接口连接2

@interface MainTableViewController ()

#import"TLPeople.h"

typedefvoid(^CodingCallBack)();

@interfaceTLPeople (Associated)

@property(nonatomic,strong)NSNumber*associatedBust;//胸围

@property(nonatomic,copy)CodingCallBackassociatedCallBack;//写代码

@end

#import <HPCastLink/HPCastLink.h>

#import <HPCastLink/HPDevicesService.h>

<HPCastSearchDelegate, HPCastLinkDelegate>

1.先是什么是第三登入?
答: 第三方登入就去博客园,微信,QQ那几个app上,拿客商的信息. 获得了接下来发到自个儿公司的服务器实现注册. 其实就是去第三方应用上拿客商的消息.
微信简单流程: 1.拿code--->2.用code换access_token--->3.用access_token换顾客相关音信--->4.登陆成功
腾讯网: 跳转到和讯顾客端---->2.得到accessToken,和userID---->3.拿客商新闻
QQ: 跳转到QQ----->2.重返调用代理方法getUserInfo, ---->3.再调用代理方法重返用户音信

@property(nonatomic,strong)NSMutableArray * dataArray;

TLPeople Associated.m如下:

在viewDidLoad中

望着地点的流程是还是不是亮点蒙?, 先别管,先记住,假设是微信的话,你要做三次网络央求让后最后拿到客户音信, 今日头条的话你只需做二回网络央浼就ok, QQ的话你就直接调情势就行了互连网央求什么的永不你烦.
2.索要什么样布置?
详尽安插能够参谋作者的---iOS-博客园新浪,QQ,微信分享原生接入记录,登陆和享受的这个配置都以平等的, 也得以参照demo,直接!
①.首先加多那四个利用的sdk
②.增多白名单
③.增加 -ObjC,编写翻译选项
④.添加 URL Tyes
⑤. 为了适配iOS9上述,你要求在info.plist里面再布局允许http访谈
⑥.增多信赖库
允许http

@end

#import"TLPeople Associated.h"

#if TARGET_IPHONE_SIMULATOR

#import <objc/objc-runtime.h>

#else

#import <objc/runtime.h>

#import <objc/message.h>

#endif

@implementationTLPeople (Associated)

-(void)setAssociatedBust:(NSNumber*)associatedBust

{

//设置关联对象

objc_setAssociatedObject(self,@selector(associatedBust), associatedBust,OBJC_ASSOCIATION_RETAIN_NONATOMIC);

}

-(NSNumber*)associatedBust

{

//获得关联对象

returnobjc_getAssociatedObject(self,@selector(associatedBust));

}

-(void)setAssociatedCallBack:(CodingCallBack)associatedCallBack

{

objc_setAssociatedObject(self,@selector(associatedCallBack), associatedCallBack,OBJC_ASSOCIATION_COPY_NONATOMIC);

}

-(CodingCallBack)associatedCallBack

{

returnobjc_getAssociatedObject(self,@selector(associatedCallBack));

}

@end

[[HPCastLink sharedCastLink]appkeyVerify:@"<#AppKey#>"];

[HPCastLink sharedCastLink].delegate = self;

[HPCastLink sharedCastLink].enableDLNA = YES;

[[HPCastLink sharedCastLink]setBackgroundPlay:NO];

[[HPCastLink sharedCastLink]castServiceDiscoveryDelegate:self];

[[HPCastLink sharedCastLink]castServiceDiscoveryBlock:^(NSArray *response) {

[self.dataArray removeAllObjects];

[self.dataArray addObjectsFromArray:response];

[self.tableView reloadData];

[[HPCastLink sharedCastLink]castServiceStopDiscovery];

}];

[[HPCastLink sharedCastLink]castStartPlay:HPCastMediaTypeVideo url:@"" startPosition:0 superViewController:self completeBlock:^(HPCastMirrorResults response) {

NSLog(@"%lu",(unsigned long)response); NSLog(@"==============%d",[HPCastLink sharedCastLink].isMirrorTv);

[[HPCastLink sharedCastLink]castDeviceVolume:0];

}];

原生接入,Runtime技能科学商讨。// 首要还天涯论坛那个人,固然她是https的,证书当然也没难点,但是他的TLS版本太低了,所以拿博客园音讯的时候,要是不布署,iOS9以上的无绳电话机就拿不到新闻.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

@implementation MainTableViewController

在main.m中运维以下代码

[听雨阁]()

Snip20160704_1.png
有关HTTPS的相关,证书什么的素材,参谋那些

- (void)viewDidLoad {

#import <Foundation/Foundation.h>

#import "TLPeople.h"

#import "TLPeople Associated.h"

int main(intargc,constchar* argv[]) {

@autoreleasepool{

TLPeople*tlTeacher = [[TLPeoplealloc]init];

tlTeacher.name=@"TridonLee";

tlTeacher.age=18;

[tlTeachersetValue:@"Teacher"forKey:@"occupation"];

tlTeacher.associatedBust=@(90);

tlTeacher.associatedCallBack= ^(){

NSLog(@"TridonLee Teacher要写代码了!");

};

tlTeacher.associatedCallBack();

NSDictionary*propertyResultDic = [tlTeacherallProperties];

for(NSString*propertyNameinpropertyResultDic.allKeys) {

NSLog(@"propertyName:%@, propertyValue:%@",propertyName, propertyResultDic[propertyName]);

}

NSDictionary*methodResultDic = [tlTeacherallMethods];

for(NSString*methodNameinmethodResultDic.allKeys) {

NSLog(@"methodName:%@, argumentsCount:%@", methodName, methodResultDic[methodName]);

}

}

return0;

}

只顾点 博客园今日头条你或者会遇见如下
1.redirect_uri_mismatch
您的回调地址错误,
消除办法:去博客园开放平台修改回调地址;
2.sso package or sign error
本条是您app 的Bundle identifier 和今日头条开放平台上的Bundle ID差异. 去开放平台上改造一下就好.
如图注意要逐项对齐

    [super viewDidLoad];

此次运维结果多出了贰个associatedBust(胸围)和三个associatedCallBack(写代码)属性。

Bundle identifier 对应

    _dataArray=[NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8", nil];

如图:

Snip20160704_4.png
回调页对应

    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

大家成功的给TridonLee增添个四个腰围的属性和八个写代码的回调,可是增加属性没有怎么意义,我们平时在付出过成功中用的可比多的就是增进回调了。

Snip20160704_8.png
app key 对应

    [self.tableView reloadData];

Demo传送门-> 5.1 扩展新功用篇德姆o

Snip20160704_5.png
代码简单介绍
和分享同样自个儿提供了叁个WTThirdPartyLoginManager管理各种平台的
登入,提供了如下的一个类措施

//    添加刷header

  • (void)getUserInfoWithWTLoginType:(WTLoginType)type result:(WTThirdPartyLoginResultBlock)result;
    1.首先你得在WTThirdPartyLoginManager.m配置好了各平台的音讯
    2.管教您的U陆风X8L Schemes 也安排好
    传扬不一致的WTLoginType跳转到分裂的顾客端!
    上面是WTThirdPartyLoginManager的切实代码
    WTThirdPartyLoginManager.h
    //
    // WTThirdPartyLoginManager.h
    // WTThird_Party_Login
    //
    // Created by Mac on 16/7/2.
    // Copyright © 2016年 wutong. All rights reserved.
    //

    MJRefreshNormalHeader * herder =[MJRefreshNormalHeader headerWithRefreshingBlock:^{

import <Foundation/Foundation.h>

        [self requestData];

import "WeiboSDK.h"

    }];

import "WXApi.h"

    self.tableView.mj_header=herder;

import <TencentOpenAPI/TencentOAuth.h>

    [herder setTitle:@"正在加载中。。。" forState:MJRefreshStateRefreshing];

import <TencentOpenAPI/QQApiInterfaceObject.h>

//    添加footer

import <TencentOpenAPI/QQApiInterface.h>

typedef NS_ENUM(NSInteger, WTLoginType) {
WTLoginTypeWeiBo = 0, // 博客园微博
WTLoginTypeTencent, // QQ
WTLoginTypeWeiXin // 微信
};

typedef NS_ENUM(NSInteger, WTLoginWeiXinErrCode) {
WTLoginWeiXinErrCodeSuccess = 0,
WTLoginWeiXinErrCodeCancel = -2,

};

typedef void(^WTThirdPartyLoginResultBlock)(NSDictionary * LoginResult, NSString * error);

@interface WTThirdPartyLoginManager : NSObject<TencentSessionDelegate, TencentLoginDelegate,WBHttpRequestDelegate,WeiboSDKDelegate,WXApiDelegate>

  • (instancetype)shareWTThirdPartyLoginManager;

  • (void)getUserInfoWithWTLoginType:(WTLoginType)type result:(WTThirdPartyLoginResultBlock)result;

@end
WTThirdPartyLoginManager.m
//
// WTThirdPartyLoginManager.m
// WTThird_Party_Login
//
// Created by Mac on 16/7/2.
// Copyright © 2016年 wutong. All rights reserved.
//

    self.tableView.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{

import "WTThirdPartyLoginManager.h"

        [self requestData];

define kSinaAppKey @"你和谐治将养讯的Appkey"//

        [self loadData];

define kSinaRedirectU中华VI @"你设置的今日头条回调页"

    }];

define k腾讯AppId @"你的腾讯开放平台的appId"

}

define kWeixinAppId @"微信id"

-(void)requestData{

define kWeixinAppSecret @"AppSecret"

@interface WTThirdPartyLoginManager () <NSCopying,NSURLSessionTaskDelegate>
{

}
@property (nonatomic, copy)WTThirdPartyLoginResultBlock resultBlock;
@property (nonatomic, assign)WTLoginType wtLoginType;
@property (nonatomic, strong)NSString * access_token;

@property (nonatomic, strong)TencentOAuth * tencentOAuth;
@property (nonatomic, strong)NSMutableArray * tencentPermissions;

@end

@implementation WTThirdPartyLoginManager

static WTThirdPartyLoginManager * _instance;

  • (void)initialize
    {
    [WTThirdPartyLoginManager shareWTThirdPartyLoginManager];
    }

  • (instancetype)allocWithZone:(struct _NSZone *)zone
    {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
    _instance = [super allocWithZone:zone];
    [_instance setRegisterApps];
    });
    return _instance;
    }

  • (instancetype)shareWTThirdPartyLoginManager
    {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
    _instance = [[self alloc]init];
    [_instance setRegisterApps];
    });
    return _instance;
    }

  • (id)copyWithZone:(nullable NSZone *)zone
    {
    return _instance;
    }

// 注册app
// 注册appid

  • (void)setRegisterApps
    {
    // 注册Sina微博
    [WeiboSDK registerApp:kSinaAppKey];
    // 微信注册
    [WXApi registerApp:kWeixinAppId];

    // 注册QQ
    _tencentOAuth = [[TencentOAuth alloc]initWithAppId:kTencentAppId andDelegate:self];
    // 那么些是提及时候你去qq那拿什么音信
    _tencentPermissions = [NSMutableArray arrayWithArray:@[/** 获取客商音信 /
    kOPEN_PERMISSION_GET_USER_INFO,
    /
    * 移动端获取顾客新闻 /
    kOPEN_PERMISSION_GET_SIMPLE_USER_INFO,
    /
    * 获取登陆客商自身的详细新闻 */
    kOPEN_PERMISSION_GET_INFO]];
    }

  • (void)getUserInfoWithWTLoginType:(WTLoginType)type result:(WTThirdPartyLoginResultBlock)result
    {
    _instance.resultBlock = result;
    _instance.wtLoginType = type;
    if (type == WTLoginTypeWeiBo) {
    WBAuthorizeRequest *request = [WBAuthorizeRequest request];
    request.redirectURI = kSinaRedirectURI;
    // request.scope = @"follow_app_official_microblog";

      [WeiboSDK sendRequest:request];
    

    }else if (type == WTLoginTypeTencent){

      [_instance.tencentOAuth authorize:_instance.tencentPermissions];
    

    }else if (type == WTLoginTypeWeiXin){
    //构造SendAuthReq结构体
    SendAuthReq* req =[[SendAuthReq alloc ] init ];
    req.scope = @"snsapi_userinfo" ;
    //第三偏向微信终端发送贰个SendAuthReq消息结构
    [WXApi sendReq:req];
    }
    }

    NSLog(@"乞请数据");

pragma mark - WXApiDelegate

-(void) onResp:(BaseResp*)resp
{
SendAuthResp *aresp = (SendAuthResp *)resp;

if (resp.errCode == WTLoginWeiXinErrCodeSuccess) {
    NSString *code = aresp.code;
    [[WTThirdPartyLoginManager shareWTThirdPartyLoginManager] getWeiXinUserInfoWithCode:code];
}else{

    if (self.resultBlock)
    {
        self.resultBlock(nil, @"授权失败");
    }
}

}

  • (void)getWeiXinUserInfoWithCode:(NSString *)code
    {
    NSOperationQueue * queue = [[NSOperationQueue alloc]init];

    NSBlockOperation * getAccessTokenOperation = [NSBlockOperation blockOperationWithBlock:^{

      NSString * urlStr = [NSString stringWithFormat:@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=%@&secret=%@&code=%@&grant_type=authorization_code",kWeixinAppId,kWeixinAppSecret,code];
      NSURL * url = [NSURL URLWithString:urlStr];
      NSString *responseStr = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
      NSData *responseData = [responseStr dataUsingEncoding:NSUTF8StringEncoding];
      NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];
      self.access_token = [dic objectForKey:@"access_token"];
    

    }];

    NSBlockOperation * getUserInfoOperation = [NSBlockOperation blockOperationWithBlock:^{
    NSString *urlStr =[NSString stringWithFormat:@"https://api.weixin.qq.com/sns/userinfo?access_token=%@&openid=%@",self.access_token,kWeixinAppId];
    NSURL * url = [NSURL URLWithString:urlStr];
    NSString *responseStr = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    NSData *responseData = [responseStr dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];
    NSDictionary *paramter = @{@"third_id" : dic[@"openid"],
    @"third_name" : dic[@"nickname"],
    @"third_image":dic[@"headimgurl"],
    @"access_token":self.access_token};

      [[NSOperationQueue mainQueue] addOperationWithBlock:^{
    
          //                _resultBlock;
          self.resultBlock(paramter, nil);
      }];
    

    }];

    [getUserInfoOperation addDependency:getAccessTokenOperation];

    [queue addOperation:getAccessTokenOperation];
    [queue addOperation:getUserInfoOperation];
    }

//    数据央求实现,结束刷新,重新刷新表格

pragma mark - TencentLoginDelegate

//委托

  • (void)tencentDidLogin
    {
    [_tencentOAuth getUserInfo];
    }

  • (void)getUserInfoResponse:(APIResponse *)response
    {
    if (response.retCode == URLREQUEST_SUCCEED)
    {
    NSLog(@"%@", response.jsonResponse);
    NSLog(@"openID %@", [_tencentOAuth openId]);
    NSDictionary *paramter = @{@"third_id" : [_tencentOAuth openId],
    @"third_name" : [response.jsonResponse valueForKeyPath:@"nickname"],
    @"third_image":[response.jsonResponse valueForKeyPath:@"figureurl_qq_2"],
    @"access_token":[_tencentOAuth accessToken]};

      if (self.resultBlock)
      {
          self.resultBlock(paramter, nil);
      }
    

    }
    else
    {
    NSLog(@"登陆战败!");
    }
    }

  • (void)tencentDidLogout
    {

}

  • (void)tencentDidNotLogin:(BOOL)cancelled
    {

}

  • (void)tencentDidNotNetWork
    {

}

    [self.tableView.mj_header endRefreshing];

pragma mark - WeiboSDKDelegate

  • (void)didReceiveWeiboRequest:(WBBaseRequest *)request
    {

}

  • (void)didReceiveWeiboResponse:(WBBaseResponse *)response
    {
    NSLog(@"token %@", [(WBAuthorizeResponse *) response accessToken]);
    NSLog(@"uid %@", [(WBAuthorizeResponse *) response userID]);

    [self getWeiBoUserInfo:[(WBAuthorizeResponse *) response userID] token:[(WBAuthorizeResponse *) response accessToken]];
    }

  • (void)getWeiBoUserInfo:(NSString *)uid token:(NSString *)token
    {
    NSString *url =[NSString stringWithFormat:@"https://api.weibo.com/2/users/show.json?uid=%@&access_token=%@&source=%@",uid,token,kSinaAppKey];
    NSURL *zoneUrl = [NSURL URLWithString:url];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[[NSOperationQueue alloc] init]];
    // 创制职务
    NSURLSessionDataTask * task = [session dataTaskWithRequest:[NSURLRequest requestWithURL:zoneUrl] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

      NSLog(@"%@", [NSThread currentThread]);
    
      NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
      NSLog(@"%@",dic);
    
      NSDictionary *paramter = @{@"third_id" : [dic valueForKeyPath:@"idstr"],
                                 @"third_name" : [dic valueForKeyPath:@"screen_name"],
                                 @"third_image":[dic valueForKeyPath:@"avatar_hd"],
                                 @"access_token":token};
    
      [[NSOperationQueue mainQueue] addOperationWithBlock:^{
          if (self.resultBlock)
          {
              _resultBlock(paramter, nil);
          }
      }];
    

    }];

    // 运行职分
    [task resume];
    }

@end
demo下载
1.demo下载下来之后,请在WTThirdPartyLoginManager里面将团结的个阳台的app key写上去.
2.U中华VL Schemes 也请各位自身配置好
demo地址

}

-(void)loadData{

    NSLog(@"恳求数据");

    [self.tableView.mj_footer endRefreshing];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

#warning Incomplete implementation, return the number of sections

    return 1;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

#warning Incomplete implementation, return the number of rows

    return _dataArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

    if (!cell) {

        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];

    }

    cell.textLabel.text=[_dataArray objectAtIndex:indexPath.row];

    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    HUDViewController *hud =[[HUDViewController alloc]init];

    [self presentViewController:hud animated:YES completion:^{

    }];

}

小秋菊控件

#import "HUDViewController.h"

#import "MBProgressHUD.h"

@interface HUDViewController ()

@end

@implementation HUDViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor=[UIColor whiteColor];

//    显示小黄花

    MBProgressHUD *HUD =[MBProgressHUD showHUDAddedTo:self.view animated:YES];

    HUD.label.text=@"二哥的黄华在转。。。。";

}

本文由星彩网app下载发布于计算机编程,转载请注明出处:原生接入,Runtime技能科学商讨

TAG标签: 星彩网app下载
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。