目录

备注

Google

Google分享

Google推送

FaceBook

FaceBook分享

Twitter

Twitter分享

Instagram

Instagram分享

SDK下载

UIWebView转WKwebView问题



备注

如果已经有使用了友盟的话,改外海外版,授权可以使用facebook和twitter,google和ins需要单独使用,如果是直接就准备做海外版,强烈推荐使用Fierbase。

Google

Google官方文档以及Demo

https://developers.google.cn/identity/sign-in/ios/sdk/

1.根据文档添加GoogleSignInDependencies.framework ,GoogleSignIn.framework ,GoogleSignIn.bundle如果不用官方按钮的话就不需要这个

2.根据文档添加依赖

3.生成client ID,点击绿色按钮,最后生成

static NSString * const kClientID =@"AAAA.apps.googleusercontent.com";

[GIDSignIn sharedInstance].clientID = kClientID;//用到的就是这个ID,生成的时候填写的bundleID需要建一个应用

4.填写URL Type保证跳转正常,格式为com.googleusercontent.apps.AAAA,AAAA就是生成kClientID的前半部分

5.代码部分

//
//  CNMShareGoogle.h
//  YoYoGame
//
//  Created by gaoshuang  on 2019/2/15.
//  Copyright © 2019 SINASHOW. All rights reserved.
//#import <Foundation/Foundation.h>
#import <GoogleSignIn/GoogleSignIn.h>@interface CNMShareGoogle : NSObject<CNMHelperProtocol>/**设置google Platform*/
-(void)cnm_setupGooglePlatforms;/**设置googleDelegate*/
-(void)cnm_setupGoogleDelegate;/**登录*/
-(void)cnm_loginWithWithBlock:(void (^)(BOOL  isSuccessed,GIDGoogleUser* userInfoResp))block;/**回调调转@param url@param sourceApplication@param annotation@return*/
- (BOOL)cnm_handleURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplicationannotation:(id)annotation;@end//
//  CNMShareGoogle.m
//  YoYoGame
//
//  Created by gaoshuang  on 2019/2/15.
//  Copyright © 2019 SINASHOW. All rights reserved.
//#import "CNMShareGoogle.h"
//static NSString * const kClientID =
//@"589453917038-qaoga89fitj2ukrsq27ko56fimmojac6.apps.googleusercontent.com";
static NSString * const kClientID =
@"868607979203-2jjajqegiv7t5to8o69409fh6lvg9hcl.apps.googleusercontent.com";
@interface CNMShareGoogle()<GIDSignInDelegate, GIDSignInUIDelegate>
@property (copy, nonatomic)void (^blockLogin)(BOOL isSuccessed,GIDGoogleUser* userInfoResp);@end
@implementation CNMShareGoogle
HELPER_SHARED(CNMShareGoogle)-(void)cnm_setupGooglePlatforms{[GIDSignIn sharedInstance].clientID = kClientID;
}
- (BOOL)cnm_handleURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplicationannotation:(id)annotation{return [[GIDSignIn sharedInstance] handleURL:urlsourceApplication:sourceApplicationannotation:annotation];return YES;
}-(void)cnm_setupGoogleDelegate{GIDSignIn *signIn = [GIDSignIn sharedInstance];signIn.shouldFetchBasicProfile = YES;signIn.delegate = self;signIn.uiDelegate = self;
}
-(void)cnm_loginWithWithBlock:(void (^)(BOOL isSuccessed,GIDGoogleUser* userInfoResp))block{self.blockLogin = nil;self.blockLogin = block;[[GIDSignIn sharedInstance] signIn];
}
#pragma mark - GIDSignDelegate- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)userwithError:(NSError *)error {// Perform any operations on signed in user here.
//    NSString *userId = user.userID;                  // For client-side use only!
//    NSString *idToken = user.authentication.idToken; // Safe to send to the server
//    NSString *fullName = user.profile.name;
//    NSString *givenName = user.profile.givenName;
//    NSString *familyName = user.profile.familyName;
//    NSString *email = user.profile.email;
//性别是取不到的,不需要根据acctoken取用户信息了if (!error) {if (self.blockLogin) {self.blockLogin(YES,user);}}else{if (self.blockLogin) {self.blockLogin(NO,user);}}// ...
}
- (void)signIn:(GIDSignIn *)signIn
didDisconnectWithUser:(GIDGoogleUser *)userwithError:(NSError *)error{if (self.blockLogin) {self.blockLogin(NO,user);}
}#pragma mark - GIDSignInUIDelegate
//该代理一般不用实现,除非自己对界面跳转或交互有一些需求
- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error {//    [myActivityIndicator stopAnimating];
}// Present a view that prompts the user to sign in with Google
- (void)signIn:(GIDSignIn *)signIn
presentViewController:(UIViewController *)viewController {[[self getCurrentVC] presentViewController:viewController animated:YES completion:nil];
}// Dismiss the "Sign in with Google" view
- (void)signIn:(GIDSignIn *)signIn
dismissViewController:(UIViewController *)viewController {[[self getCurrentVC] dismissViewControllerAnimated:YES completion:nil];
}
@end

Google分享

关闭

Google推送

流程,控制台添加应用,生成GoogleService-Info.list加入工程

控制台配置生产和发布证书

//需要外网环境才能返回
#pragma mark FIRMessagingDelegate
// [END ios_10_message_handling]
// [START refresh_token]
//获取注册令牌
- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken

获取到令牌在控制台测试发消息

客户端获取令牌提交到服务器

https://www.jianshu.com/p/8281047bcdec

https://www.freesion.com/article/8801507287/

FaceBook

由于FaceBook使用到了友盟 传送门 (不建议混合使用,会很乱,海外版的直接用Firebase集成吧)

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];[login logOut];//避免出现 FBSDK Login Error Code: 308[login logInWithReadPermissions: @[@"public_profile",@"email"]
fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result,
NSError *error) {if (error) {NSLog(@"Process error");} else if (result.isCancelled) {NSLog(@"Cancelled");} else {NSLog(@"Logged in");NSDictionary*params=[NSDictionary new];FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]initWithGraphPath:result.token.userIDparameters:paramsHTTPMethod:@"GET"];[request
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,id result,NSError *error) {NSString*name=[result objectForKey:@"name"];NSString*userid=[result objectForKey:@"id"];NSLog(@"name=%@ userID=%@ ",name,userid);}];      }}];

FaceBook分享

使用官方sdkdemo的分享 传送门

友盟分享统一调用


//sharWebUrl 一定得是https://标准格式,不然会跳转不进去,很坑,而且进入编辑界面点击返回键,放弃编辑,如果点击左上角返回应用会卡住FBSDKShareLinkContent *linkContent = [[FBSDKShareLinkContent alloc] init];linkContent.contentURL = [NSURL URLWithString:sharWebUrl];linkContent.contentTitle = titile;linkContent.contentDescription = content;linkContent.imageURL = [NSURL URLWithString:imageUrl];FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];dialog.fromViewController = [self gs_getCurrentVC];dialog.shareContent = linkContent;BOOL isInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fbapi://"]];if (isInstalled){dialog.mode = FBSDKShareDialogModeNative;}else{dialog.mode = FBSDKShareDialogModeAutomatic;}[dialog show];

https://www.jianshu.com/p/dd35278ee0a3

使用官方sdkdemo 传送门

Twitter

Twitter也使用到了友盟,但是友盟返回值中缺失authTokenSecret,需要手动掉用loadUserWithID方法

urltype设置  twitterkit-APPKEY

独立
Twitter  3.0 sdk的话- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.[[Twitter sharedInstance] startWithConsumerKey:@"guLppo4I" consumerSecret:@"xWpL85O3d3j6L0xTXC17j"];return YES;
}- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
//    return [[Twitter sharedInstance] application:app openURL:url options:options];if ([[Twitter sharedInstance] application:app openURL:url options:options]) {return YES;}// If you handle other (non Twitter Kit) URLs elsewhere in your app, return YES. Otherwisereturn NO;
}//自定义xib按钮触发事件
- (IBAction)loginAction:(id)sender {[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {if(session){NSLog(@"%@已登录",session.userName);[self loadTwitterUserWithID:session.userID];}  else  {NSLog(@"error:%@",error.localizedDescription);}}];}//获取Twitter用户信息
- (void)loadTwitterUserWithID:(NSString *)userId{TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];[client loadUserWithID:userId completion:^(TWTRUser * _Nullable user, NSError * _Nullable error) {if (user) {NSLog(@"头像url:%@",user.profileImageURL);}else{NSLog(@"error:%@",error.localizedDescription);}}];
}//管理多个用户时需要注销用户
- (void)logoutTwitterUser{TWTRSessionStore *store = [[Twitter sharedInstance] sessionStore];NSString *userID = store.session.userID;[store logOutUserID:userID];
}

https://www.jianshu.com/p/50f67bd865ac

Twitter分享

 NSString* strDescription =@"用DataYuk,邂逅属于你的爱,快来相亲,交友,谈恋爱吧";NSString* strWebURL = @"https://winkydate.com";// ExampleNSMutableArray *parameter = [NSMutableArray array];if (![strDescription isEqualToString:@""]) {[parameter addObject:[NSString stringWithFormat:@"text=%@", strDescription]];}if (![strWebURL isEqualToString:@""]) {[parameter addObject:[NSString stringWithFormat:@"url=%@", strWebURL]];}NSString *shareWebLink = [[NSString stringWithFormat:@"https://twitter.com/intent/tweet?%@",[parameter componentsJoinedByString:@"&"]]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:shareWebLink]]) {[[UIApplication sharedApplication] openURL:[NSURL URLWithString:shareWebLink]];}return;//        //检查是否当前会话具有登录的用户
//        if ([[Twitter sharedInstance].sessionStore hasLoggedInUsers]) {
//            TWTRComposer *composer = [[TWTRComposer alloc] init];
//            [composer setText:messageObject.text];
//           //带图片方法
//            [composer setImage: shareObject.thumbImage ];
//            [composer setURL:[NSURL URLWithString:@"https://winkydate.com"]];
//            [composer showFromViewController:self completion:^(TWTRComposerResult result){
//                if(result == TWTRComposerResultCancelled) {
//                   //分享失败
//               }else{
//                   //分享成功
//                }
//            }];
//         }else{
//           [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
//               if (session) {
//                        TWTRComposer *composer = [[TWTRComposer alloc] init];
//                        [composer setText:messageObject.text];
//                       //带图片方法
//                         [composer setImage: shareObject.thumbImage ];
//                                  [composer setURL:[NSURL URLWithString:@"https://winkydate.com"]];
//                        [composer showFromViewController:self completion:^(TWTRComposerResult result){
//                             if(result == TWTRComposerResultCancelled) {
//                                //分享失败
//                            }else{
//                            //分享成功
//                            }
//                        }];
//                        NSLog(@"signed in as %@", [session userName]);
//                   } else {
//                        NSLog(@"error: %@", [error localizedDescription]);
//                   }
//               }];
//           }//        [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_Twitter messageObject:messageObject currentViewController:[self gs_getCurrentVC] completion:^(id data, NSError *error) {
//            if (error) {
//                //  [[self gs_getCurrentVC] showToast:error.userInfo[@"message"]];
//            }else{
//                [[self gs_getCurrentVC] showToast:gs_language(@"分享成功")];
//            }
//        }];

https://www.jianshu.com/p/4ccdb3a6dc67

https://www.jianshu.com/p/2d8992a278f4

https://www.jianshu.com/p/50f67bd865ac

Instagram

Instagram官方文档

Demo


#import <UIKit/UIKit.h>
@interface UserModel: NSObject
@property (strong, nonatomic)NSString* full_name;
@property (strong, nonatomic)NSString* idD;
@property (strong, nonatomic)NSString* is_business;
@property (strong, nonatomic)NSString* profile_picture;
@property (strong, nonatomic)NSString* username;
@property (strong, nonatomic)NSString* website;
@property (strong, nonatomic)NSString* access_token;
@end
@interface IKLoginViewController : UIViewController
@property (strong, nonatomic)void (^Block)(BOOL isSuccessed, UserModel* model);
@end#import "IKLoginViewController.h"
#import <WebKit/WebKit.h>
@implementation UserModel
@end
@interface IKLoginViewController () <WKNavigationDelegate>@end@implementation IKLoginViewController- (void)viewDidLoad
{[super viewDidLoad];WKWebViewConfiguration *webConfiguration = [[WKWebViewConfiguration alloc] init];webConfiguration.websiteDataStore = [WKWebsiteDataStore defaultDataStore];WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:webConfiguration];webView.scrollView.bounces = NO;self.navigationItem.title = @"Instagram";[self.navigationItem.rightBarButtonItem setEnabled:NO];NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.instagram.com/oauth/authorize/?client_id=%@&redirect_uri=%@&response_type=code",@"883a3fe2c91f45a38a4354c82a9da7a3",@"http://www.funplanet.cn/"]];NSURLRequest *request = [NSURLRequest requestWithURL:url];[self.view addSubview:webView];webView.navigationDelegate = self;[webView loadRequest:request];
}- (void)authenticationSuccess
{[self.navigationItem setLeftBarButtonItem:nil];[self.navigationItem.rightBarButtonItem setEnabled:YES];
}- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
{if ([navigationResponse.response.URL.absoluteString hasPrefix:@"http://www.funplanet.cn/?code="]){}decisionHandler(WKNavigationActionPolicyAllow);
}- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler
{NSString* str =navigationAction.request.URL.absoluteString;if ([navigationAction.request.URL.absoluteString hasPrefix:@"http://www.funplanet.cn/?code="]){str = [str substringFromIndex:[str rangeOfString:@"code="].location+5];NSDictionary* dict = @{@"client_id":@"883a3fe2c91f45a38a43AAAAA",//应用id,登录的测试账号需要被邀请加入沙盒环境,或者用审核应用id的账号@"client_secret":@"345f20582ed343e8a494f20BBBBB",//应用私钥@"code":[str toString],//重定向后取到的codeid@"grant_type":@"authorization_code",//固定的值@"redirect_uri":@"http://www.funplanet.cn/"//固定回调的url};[self POSTDictionary:@"https://api.instagram.com/oauth/access_token" params:dict tag:1 HTTPS:YES success:^(AFHTTPRequestOperation *operation, id responseObject) {if (responseObject) {UserModel* model = [[UserModel alloc]init];model.access_token =responseObject[@"access_token"];model.full_name =responseObject[@"user"][@"full_name"];model.idD = [responseObject[@"user"][@"id"]  toString];model.is_business =responseObject[@"user"][@"is_business"];model.profile_picture =responseObject[@"user"][@"profile_picture"];model.username =responseObject[@"user"][@"username"];if (_Block) {_Block(YES, model);[self popCanvas];}}else{if (_Block) {_Block(NO, nil);[self popCanvas];}}} failure:^(AFHTTPRequestOperation *operation, NSError *error) {if (_Block) {_Block(NO, nil);[self popCanvas];}}];decisionHandler(WKNavigationActionPolicyCancel);}decisionHandler(WKNavigationActionPolicyAllow);
}- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation {}- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
{
//    if ([navigationResponse.response.URL.absoluteString hasPrefix:@"http://www.funplanet.cn/?code="]){
//
//    }
}
@end

Instagram 唤起不了客户端,只能网页进行,退出登录的方法

    WKWebsiteDataStore *dateStore = [WKWebsiteDataStore defaultDataStore];[dateStore fetchDataRecordsOfTypes:[WKWebsiteDataStore allWebsiteDataTypes]completionHandler:^(NSArray<WKWebsiteDataRecord *> * __nonnull records) {for (WKWebsiteDataRecord *record  in records){if ( [record.displayName containsString:@"instagram.com"]) //取消备注,可以针对某域名清除,否则是全清{[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:record.dataTypesforDataRecords:@[record]completionHandler:^{NSLog(@"Cookies for %@ deleted successfully",record.displayName);}];}}}];

Instagram分享

   NSString *shareWebLink = [NSString stringWithFormat:@"instagram://app"];if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:shareWebLink]]) {[[UIApplication sharedApplication] openURL:[NSURL URLWithString:shareWebLink]];}
另外有进入发布页面选择相册以及固定相册图片的方法

SDK下载

Google https://developers.google.cn/identity/sign-in/ios/sdk/

FaceBook https://github.com/facebook/facebook-ios-sdk

编译需要添加一个空的swift文件(Swift module的问题)

如果遇上Redefinition of module 'Swift',建议重新pod一下

Twitter  https://github.com/twitter-archive/twitter-kit-ios

UIWebView转WKwebView问题

ITMS-90809: Deprecated API Usage - New apps that use UIWebView are no longer accepted. Instead, use WKWebView for improved security and reliability. 传送门

IOS-海外版授权分享推送统计 Google FaceBook Twitter Instagram相关推荐

  1. 苹果iOS系统下的推送机制及实现

    苹果iOS系统下的推送机制及实现 浏览:785次  出处信息 width="336" height="280" frameborder="0" ...

  2. iOS开发之消息推送 —— 远程消息推送入门

    每次看到iOS的远程消息推送,总是感觉很头大,即便后来项目都做完了,还是觉得摸不着远程推送的脉门,网上介绍的资料虽多,但不是写的太简单了,就是写的太详细了,不能一下抓住要点,今天终于能够抽出点时间,来 ...

  3. IOS开发之----远程推送通知

    原文地址:IOS开发之----远程推送通知作者:倒計時 玩了一年的iPhone了各种App的远程通知接收了不少,每次接收到的时候,就在反思,这丫的怎么实现的! 由于工作方面一直没有接触的机会,所以只好 ...

  4. 李洪强iOS之集成极光推送二iOS 证书 设置指南

    李洪强iOS之集成极光推送二iOS 证书 设置指南 创建应用程序ID 登陆 iOS Dev Center 选择进入iOS Provisioning Portal. 在 iOS Provisioning ...

  5. 传腾讯计划出售美团全部股权,知情人士辟谣;苹果证实iOS 16要大量推送广告;Linux 6.0-rc1 发布|极客头条

    「极客头条」-- 技术人员的新闻圈! CSDN 的读者朋友们早上好哇,「极客头条」来啦,快来看今天都有哪些值得我们技术人关注的重要新闻吧. 整理 | 梦依丹 出品 | CSDN(ID:CSDNnews ...

  6. 传腾讯计划出售美团全部股权,知情人士辟谣;苹果证实iOS 16要大量推送广告;Linux 6.0-rc1 发布|极客头条...

    「极客头条」-- 技术人员的新闻圈! CSDN 的读者朋友们早上好哇,「极客头条」来啦,快来看今天都有哪些值得我们技术人关注的重要新闻吧. 整理 | 梦依丹 出品 | CSDN(ID:CSDNnews ...

  7. iOS开发实用技术之推送-应用间跳转-社交分享

    实用补充 --- 一. 推送通知 1. 什么是推送通知? > 首先明确:**此处的推送通知跟我们的"NSNotification"没有半毛钱关系> 可以理解为: 向用户 ...

  8. (转)iOS开发资源:推送通知相关开源项目--PushSharp、APNS-PHP以及Pyapns等

    PushSharp  (github) PushSharp是一个实现了由服务器端向移动客户端推送消息的开源C#库,支持 iOS (iPhone/iPad APNS). Android (C2DM/GC ...

  9. 苹果iOS 13正式版推送:深色模式来了 速度再次提升!

    最近手机圈还真是比较热闹,苹果.华为年度旗舰发布后,9月20号0点,华为Mate 30系列开启预售,另一边iPhone 11系列也在今天正式开卖,之前首批预订的用户,将会在今天陆续收到新机:同时,苹果 ...

最新文章

  1. 全链路监控细节和难点剖析!
  2. python交互式和文件式_使用Python创建和自动化交互式仪表盘
  3. illegal to have multiple occurrences of contentType with different values 解决
  4. java 委托_java 能不能自己写一个类叫 java.lang.System/String 正确答案
  5. 常微分方程第三版_常微分方程:(第六章)非线性微分方程:5节
  6. 详解float**类型和float*类型
  7. 网站日志统计案例分析与实现
  8. 马哥学习----李洋个人笔记----安全和加密
  9. 【UE】初识Slate编辑器-理解一个最基础的编辑器界面
  10. photoShop支持retina显示屏
  11. 1+X 网络系统 建设与运维(中级)实验
  12. larval 捕获mysql错误_larval中怎样捕获mysql错误
  13. SAS统计描述、作图与均值显著性检验
  14. STM32外部中断干扰解决方案
  15. Spring iBatis Sqlmap 以及 parameterClass 和 parameterMap 的使用方法
  16. Python中利用Opencv进行车牌号检测
  17. 易语言助手用法与方便之处
  18. 考研数据结构之队列(3.3)——练习题之设计一个循环队列,用front和rear分别作为队头和队尾指针,另外用一个标志tag表示队列是空还是不空来设计队列的结构和相关基本运算算法(C表示)
  19. c语言程序由一个或多个函数,一个C源程序可由一个或多个函数组成。()
  20. 柔性电子:压电效应, 石墨烯纳米薄片和钛酸钡纳米颗粒对压电增强的协同效应

热门文章

  1. 如何将桌面文件不放在C盘
  2. 拣阅一:缘由和系统设计
  3. 芜湖!小小炫耀一下~
  4. VSAM:视频监控系统 A System for Video Surveillance and Monitoring
  5. Steemit 会颠覆 Quora/知乎 甚至 Facebook 吗?
  6. 华为HMS的电商故事:新入口、新引擎、新体验
  7. iphone播客怎么上传_如何在iPhone,iPad或Android上收听播客
  8. 关于云服务器介绍?什么是阿里云服务器管理?
  9. 使用ztree异步加载数据库数据形成树形菜单
  10. 多线程产生死锁的四个必要条件