iOS:ShareSDk的分享

简介:

使用分享类的SDK其实有很多,例如友盟、ShareSDK等等,参照他们的文档集成起来并不是很难,可能出的一些问题也就是配置文件的问题,这里我个人使用了ShareSDK分享,具体操作可出现的问题如下:

1.首先去ShareSDK官方网站注册开发者账号,获取AppKey用来注册SDK:http://www.mob.com/#/

2.下载SDK:http://www.mob.com/#/downloadDetail/ShareSDK/ios

(1) ShareSDK.framework:核心静态库。(必要)
(2) Support 文件夹。其中包含三个文件夹 :
     (a) Required (需要的类库) :
         ----- MOBFoundation.framework:基础功能框架。(必要)
         ----- ShareSDK.bundle:ShareSDK资源文件。(必要)
         ----- ShareSDKConnector.framework:用于ShareSDK框架与外部框架连接的代理框架插件。(使用第三方SDK时必要。)
 
     (b) Optional (可选类库):
         ----- ShareSDKExtension.framework:对ShareSDK功能的扩展框架插件。
        (主要提供第三方平台登录、 一键分享、截屏分享、摇一摇分享等相关功能。需要使用以上功能时必要。)
         ----- ShareSDKInterfaceAdapter.framework:ShareSDK v2.x对简洁版的接口兼容包。
         ----- ShareSDKUI.bundle:分享菜单栏和分享编辑页面资源包。(如果自定义这些UI可直接移除)
         ----- ShareSDKUI.framework:分享菜单栏和分享编辑页面。(如果自定义这些UI可直接移除)
 
     (c) PlatformSDK 第三方平台SDK。(不需要的平台的SDK可直接移除)

 

3.去新浪微博开放平台、腾讯开放平台、微信开放平台等去注册账号,获取AppKey、AppID、APPScret等

平台

开放平台地址

APPkey 申请流程

新浪微博

http://open.weibo.com

http://bbs.mob.com/thread-89-1-4.html

新浪微博开放平台接入tips

腾讯微博

http://dev.t.qq.com

http://bbs.mob.com/thread-265-1-1.html

QQ空间[2]

http://open.qq.com/

http://bbs.mob.com/thread-98-1-4.html

微信[3]

http://open.weixin.qq.com

http://bbs.mob.com/thread-95-1-4.html

Facebook

https://developers.facebook.com

如何创建facebook的应用  

facebook审核流程:iOS  Android

Twitter

https://dev.twitter.com

http://bbs.mob.com/thread-119-1-3.html

google+ https://console.developers.google.com/

http://bbs.mob.com/forum.php?mod=viewthread&tid=20731&page=1&extra=#pid45156

豆瓣


http://bbs.mob.com/thread-253-1-1.html

有道云笔记

http://note.youdao.com/open/developguide.html#app

http://bbs.mob.com/thread-256-1-1.html

印象笔记

https://dev.evernote.com/

http://bbs.mob.com/thread-263-1-1.html

Linkedin

https://www.linkedin.com/secure/developer?newapp=

http://bbs.mob.com/forum.php?mod=viewthread&tid=20729&extra=page%3D1

Flickr

http://www.flickr.com/services/

http://bbs.mob.com/thread-245-1-2.html

Pinterest

http://developers.pinterest.com/

http://bbs.mob.com/forum.php?mod=viewthread&tid=20730&page=1&extra=#pid45154

Tumblr

http://www.tumblr.com/developers

http://bbs.mob.com/thread-248-1-2.html

Dropbox

https://www.dropbox.com/developers

http://bbs.mob.com/thread-249-1-2.html

Instagram

http://instagram.com/developer#

http://bbs.mob.com/thread-250-1-1.html

VKontakte

http://vk.com/dev

http://bbs.mob.com/thread-251-1-1.html

易信好友[4]


http://bbs.mob.com/thread-236-1-2.html

明道

http://open.mingdao.com/

http://bbs.mob.com/thread-257-1-1.html

人人网

http://dev.renren.com

http://bbs.mob.com/thread-309-1-1.html

开心网

http://open.kaixin001.com

http://bbs.mob.com/thread-308-1-1.html

搜狐随身看 https://open.sohu.com/

http://bbs.mob.com/thread-331-1-1.html

 

4.在plist文件配置属性

(1)Htpp协议,如果适配iSO9,需要暂时回退到http协议 info plist加

        NSAppTransportSecurity
        
             NSAllowsArbitraryLoads
             
       

(2)设置白名单在plist文件的URL Types中设置URL Schemes白名单:具体设置可以参照官方文档,很详细
(3)涉及到客户端跳转,一定要设置scheme到LSApplicationQueriesSchemes,只有设置了这个,在真机才能实现客户端的跳转,进入QQ、微信、新浪等
    进入QQ客户端:

           

   进入微信客户端:

           

  新浪微博客户端:

      


好了,一定准备就绪,直接上代码:
//1.创建一个AppDelegate分类

复制代码

#import "AppDelegate.h"

//shareSDK
#import 
#import 

//腾讯开放平台(对应QQ和QQ空间)SDK头文件
#import 
#import 

//微信SDK头文件
#import "WXApi.h"

//新浪微博SDK头文件
//新浪微博SDK需要在项目Build Settings中的Other Linker Flags添加"-ObjC"
#import "WeiboSDK.h"

@interface AppDelegate (KJShareSDk)

-(void)shareApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

@end

复制代码

复制代码

//  AppDelegate+KJShareSDk.m
//  KenJiao
//
//  Created by mac on 16/4/26.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "AppDelegate+KJShareSDk.h"

@implementation AppDelegate (KJShareSDk)

-(void)shareApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    
    /**
     *  设置ShareSDK的appKey,如果尚未在ShareSDK官网注册过App,请移步到http://mob.com/login 登录后台进行应用注册,
     *  在将生成的AppKey传入到此方法中。
     *  方法中的第二个第三个参数为需要连接社交平台SDK时触发,
     *  在此事件中写入连接代码。第四个参数则为配置本地社交平台时触发,根据返回的平台类型来配置平台信息。
     *  如果您使用的时服务端托管平台信息时,第二、四项参数可以传入nil,第三项参数则根据服务端托管平台来决定要连接的社交SDK。
     */
    [ShareSDK registerApp:@"121f16c6xxxxx"
     
          activePlatforms:@[
                            @(SSDKPlatformTypeSinaWeibo),
                            @(SSDKPlatformTypeWechat),
                            @(SSDKPlatformTypeQQ)]
                 onImport:^(SSDKPlatformType platformType)
     {
         switch (platformType)
         {
             case SSDKPlatformTypeWechat:
                 [ShareSDKConnector connectWeChat:[WXApi class]];
                 break;
             case SSDKPlatformTypeQQ:
                 [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
                 break;
             case SSDKPlatformTypeSinaWeibo:
                 [ShareSDKConnector connectWeibo:[WeiboSDK class]];
                 break;
             default:
                 break;
         }
     }
          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
     {
         
         switch (platformType)
         {
             case SSDKPlatformTypeSinaWeibo:
                 //设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
                 [appInfo SSDKSetupSinaWeiboByAppKey:@"117501xxx"
                                            appSecret:@"ac85119d8a70e9c954bbf62364xxxx"
                                            redirectUri:@"http://www.baidu.com"
                                            authType:SSDKAuthTypeBoth];
                 break;
             case SSDKPlatformTypeWechat:
                 [appInfo SSDKSetupWeChatByAppId:@"wx365f7b8b89dxxxx"
                                       appSecret:@"652feede37bd1ff5484abb1ed51xxxxf"];
                 break;
             case SSDKPlatformTypeQQ:
                 [appInfo SSDKSetupQQByAppId:@"1105359xxx"
                                      appKey:@"ewgzpB2GOf3SIxxx"
                                    authType:SSDKAuthTypeBoth];
                 break;
             default:
                 break;
         }
     }];
}

@end

复制代码

//2.在AppDelegate类中直接调用即可

复制代码

#import "AppDelegate.h"
#import "AppDelegate+KJShareSDk.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //注册shareSDK
    [self shareApplication:application didFinishLaunchingWithOptions:launchOptions];
    
    return YES;
}
@end

复制代码

//3、最后一步就是分享内容了

复制代码

//点击微信
-(void)weiixnBtnClicked:(UIButton *)sender{
    
    //1.隐藏分享视图
    [self cancelBtnClicked:nil];
    

    //2、创建分享参数
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:[NSString stringWithFormat:@"班级号:%@",self.currentClass.class_id]
                                     images:nil
                                        url:nil
                                      title:@"将该班级号分享到微信"
                                       type:SSDKContentTypeAuto];
    //3、分享(微信平台)
    [self startSharePlatform:SSDKPlatformTypeWechat parameters:shareParams];
    
}
//点击QQ
-(void)QQBtnClicked:(UIButton *)sender{
    
    //1.隐藏分享视图
    [self cancelBtnClicked:nil];
    
    
     //2、创建分享参数
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:[NSString stringWithFormat:@"班级号:%@",self.currentClass.class_id]
                                     images:nil
                                        url:nil
                                      title:@"将该班级号分享到QQ"
                                       type:SSDKContentTypeAuto];
 
    //3、分享(QQ平台)
    [self startSharePlatform:SSDKPlatformTypeQQ parameters:shareParams];
}
//点击微博
-(void)weiBoBtnClicked:(UIButton *)sender{
    
    //1.隐藏分享视图
    [self cancelBtnClicked:nil];
    
    
    //2、创建分享参数
     NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
   [shareParams SSDKEnableUseClientShare];//登录客户端
   [shareParams SSDKSetupShareParamsByText:[NSString stringWithFormat:@"班级号:%@",self.currentClass.class_id]
                                     images:nil
                                        url:nil
                                      title:@"将该班级号分享到微博"
                                       type:SSDKContentTypeAuto];
    //3、分享(新浪微博平台)
    [self startSharePlatform:SSDKPlatformTypeSinaWeibo parameters:shareParams];
    
}
//开始分享
-(void)startSharePlatform:(SSDKPlatformType)platform parameters:(NSMutableDictionary *)parameters{
    
    [ShareSDK share:platform parameters:parameters onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
        
        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];
                break;
            }
            default:
                break;
        }
    }];
}
//点击取消
-(void)cancelBtnClicked:(UIButton *)sender{
    
    [self.inviteStuView removeFromSuperview];
    [self.inviteStuView.backgroundView removeFromSuperview];
} 

复制代码

手机测试截图:例如立即邀请后,使用新浪微博分享班级号,此时打开新浪微博客户端。QQ和微信也是一样的

 

 

总结:

总结:像适配iOS9此类问题 使用第三方的直接看别人官网就行了,要不访问提供方的如微信,QQ,支付宝API官方看开发文档
如果是用sharesdk 友盟此类的 去看他们的开发文档都会第一时间给开发者提供解决方案的

sharesdk分享 iOS9适配文档地址
http://wiki.mob.com/ios9-%E5%AF%B9sharesdk%E7%9A%84%E5%BD%B1%E5%93%8D%EF%BC%88%E9%80%82%E9%85%8Dios-9%E5%BF%85%E8%AF%BB%EF%BC%89/

友盟分享 iOS9适配地址

 

本人原创,转载须注明出处,谢谢!

程序猿神奇的手,每时每刻,这双手都在改变着世界的交互方式!

本文转自当天真遇到现实博客园博客,原文链接:http://www.cnblogs.com/XYQ-208910/p/5437194.html,如需转载请自行联系原作者

相关文章
|
iOS开发
iOS开发-使用ShareSDK做分享如何让新浪分享后是可点击蓝色文字
iOS开发-使用ShareSDK做分享如何让新浪分享后是可点击蓝色文字
123 0
iOS开发-使用ShareSDK做分享如何让新浪分享后是可点击蓝色文字
|
C# 开发工具 图形学
|
1月前
|
iOS开发 开发者
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
134 67
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
|
3月前
|
开发框架 前端开发 Android开发
安卓与iOS开发中的跨平台策略
在移动应用开发的战场上,安卓和iOS两大阵营各据一方。随着技术的演进,跨平台开发框架成为开发者的新宠,旨在实现一次编码、多平台部署的梦想。本文将探讨跨平台开发的优势与挑战,并分享实用的开发技巧,帮助开发者在安卓和iOS的世界中游刃有余。
|
2月前
|
iOS开发 开发者 MacOS
深入探索iOS开发中的SwiftUI框架
【10月更文挑战第21天】 本文将带领读者深入了解Apple最新推出的SwiftUI框架,这一革命性的用户界面构建工具为iOS开发者提供了一种声明式、高效且直观的方式来创建复杂的用户界面。通过分析SwiftUI的核心概念、主要特性以及在实际项目中的应用示例,我们将展示如何利用SwiftUI简化UI代码,提高开发效率,并保持应用程序的高性能和响应性。无论你是iOS开发的新手还是有经验的开发者,本文都将为你提供宝贵的见解和实用的指导。
142 66
|
2月前
|
存储 监控 API
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
79 11

热门文章

最新文章