当前位置:澳门新葡亰网站所有平台 > 网址大全 > 网址大全:iOS第三方分享

网址大全:iOS第三方分享

文章作者:网址大全 上传时间:2019-11-20

网站链接:

出于新版的简要分享超多成效都有,並且打包后体积比全版本的少了几M据此在这里间用那些

1.在官方网站下载SDK并导入相应的framework(比起前边的少了不菲库卡塔尔

网址大全 1网址大全 2

2.初步化ShareSDK(因为,平时享受的话就那多少个平台,全部集成下卡塔 尔(阿拉伯语:قطر‎

AppDelegate中程导弹入头文件

//ShareSDK必要头文件
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKConnector/ShareSDKConnector.h>
//腾讯开放平台(对应QQ和QQ空间)SDK头文件
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>
//微信SDK头文件
#import "WXApi.h"
//新浪微博SDK头文件
#import "WeiboSDK.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *网址大全,)launchOptions NS_AVAILABLE_IOS(3_0);

 [ShareSDK registerApp:@"iosv1101"
          activePlatforms:@[
                            @(SSDKPlatformTypeSinaWeibo),
                            @(SSDKPlatformTypeTencentWeibo),
                            @(SSDKPlatformTypeMail),
                            @(SSDKPlatformTypeSMS),
                            @(SSDKPlatformTypeCopy),
                            @(SSDKPlatformTypeFacebook),
                            @(SSDKPlatformTypeTwitter),
                            @(SSDKPlatformTypeWechat),
                            @(SSDKPlatformTypeQQ),
                            @(SSDKPlatformTypeDouBan)]
                 onImport:^(SSDKPlatformType platformType) {

                     switch (platformType)
                     {
                         case SSDKPlatformTypeWechat:
                             [ShareSDKConnector connectWeChat:[WXApi class]];
                             break;
                         case SSDKPlatformTypeQQ:
                             [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
                             break;
                         default:
                             break;
                     }

                 }
          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) {

              switch (platformType)
              {
                  case SSDKPlatformTypeSinaWeibo:
                      //设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
                      [appInfo SSDKSetupSinaWeiboByAppKey:@"568898243"
                                                appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                                              redirectUri:@"http://www.sharesdk.cn"
                                                 authType:SSDKAuthTypeBoth];
                      break;
                  case SSDKPlatformTypeTencentWeibo:
                      //设置腾讯微博应用信息,其中authType设置为只用Web形式授权
                      [appInfo SSDKSetupTencentWeiboByAppKey:@"801307650"
                                                   appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
                                                 redirectUri:@"http://www.sharesdk.cn"];
                      break;
                  case SSDKPlatformTypeFacebook:
                      //设置Facebook应用信息,其中authType设置为只用SSO形式授权
                      [appInfo SSDKSetupFacebookByAppKey:@"107704292745179"
                                               appSecret:@"38053202e1a5fe26c80c753071f0b573"
                                                authType:SSDKAuthTypeBoth];
                      break;
                  case SSDKPlatformTypeTwitter:
                      [appInfo SSDKSetupTwitterByConsumerKey:@"LRBM0H75rWrU9gNHvlEAA2aOy"
                                              consumerSecret:@"gbeWsZvA9ELJSdoBzJ5oLKX0TU09UOwrzdGfo9Tg7DjyGuMe8G"
                                                 redirectUri:@"http://mob.com"];
                      break;
                  case SSDKPlatformTypeWechat:
                      [appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885"
                                            appSecret:@"64020361b8ec4c99936c0e3999a9f249"];
                      break;
                  case SSDKPlatformTypeQQ:
                      [appInfo SSDKSetupQQByAppId:@"100371282"
                                           appKey:@"aed9b0303e3ed1e27bae87c33761161d"
                                         authType:SSDKAuthTypeBoth];
                      break;
                  case SSDKPlatformTypeDouBan:
                      [appInfo SSDKSetupDouBanByApiKey:@"02e2cbe5ca06de5908a863b15e149b0b"
                                                secret:@"9f1e7b4f71304f2f"
                                           redirectUri:@"http://www.sharesdk.cn"];
                      break;
                  default:
                      break;
              }

          }];

上述是ShareSDK测验用的key,本身做程序的时候须要在ShareSDK申请,各种平台的key也要在各类平台报名

3.ShareSDK的使用

导入头文件

#import <ShareSDK/ShareSDK.h>
#import <ShareSDKExtension/SSEShareHelper.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import <ShareSDKUI/SSUIShareActionSheetStyle.h>

#pragma mark - 菜单分享
- (void)menuShareTest {
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:@"分享内容"
                                     images:nil
                                        url:[NSURL URLWithString:@"http://mob.com"]
                                      title:@"分享标题"
                                       type:SSDKContentTypeImage];

    [ShareSDK showShareActionSheet:nil
                                                                items:@[
                                                                             @(SSDKPlatformTypeSinaWeibo),
                                                                             @(SSDKPlatformTypeTencentWeibo),
                                                                             @(SSDKPlatformSubTypeWechatSession),
                                                                             @(SSDKPlatformSubTypeWechatTimeline),       @(SSDKPlatformSubTypeQQFriend),
                                                                             @(SSDKPlatformSubTypeQZone),
                                                                             @(SSDKPlatformTypeWechat)]
                                                               shareParams:shareParams
                                                       onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                                                           NSLog(@"-0-");
                                                       }];
    //删除和添加
//    [sheet.directSharePlatforms removeObject:@(SSDKPlatformTypeWechat)];
//    [sheet.directSharePlatforms addObject:@(SSDKPlatformTypeSinaWeibo)];
}

#pragma mark - 单个分享
- (void)onlyShareTest {
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:@"分享内容"
                                         images:nil
                                            url:[NSURL URLWithString:@"http://mob.com"]
                                          title:@"分享标题"
                                           type:SSDKContentTypeImage];
    [ShareSDK share:SSDKPlatformTypeSinaWeibo parameters:shareParams 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 *alertView = [[UIAlertView alloc] initWithTitle:@"分享失败"
                                                                    message:[NSString stringWithFormat:@"%@", error]
                                                                   delegate:nil
                                                          cancelButtonTitle:@"确定"
                                                          otherButtonTitles:nil];
                [alertView show];
                break;
            }
            case SSDKResponseStateCancel:
            {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享已取消"
                                                                    message:nil
                                                                   delegate:nil
                                                          cancelButtonTitle:@"确定"
                                                          otherButtonTitles:nil];
                [alertView show];
                break;
            }
            default:
                break;
        }
    }];
}


#pragma mark - 一键分享

- (void)onceShareTest {

    //构造分享参数
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:@"我在使用ShareSDK的一键分享。"
                                         images:nil
                                            url:nil
                                          title:nil
                                           type:SSDKContentTypeImage];

    [SSEShareHelper oneKeyShare:@[@(SSDKPlatformTypeSinaWeibo), @(SSDKPlatformTypeTencentWeibo)] parameters:nil onStateChanged:^(SSDKPlatformType platformType, SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
        NSString *platformName = nil;
        switch (platformType)
        {
            case SSDKPlatformTypeSinaWeibo:
                platformName = @"新浪微博";
                break;
            case SSDKPlatformTypeTencentWeibo:
                platformName = @"腾讯微博";
                break;
            default:
                break;
        }
    }];
}

#pragma mark - 第三方登录(信息获取)

- (void)threeShareTest {
    [ShareSDK getUserInfo:SSDKPlatformTypeSinaWeibo onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
        NSLog(@"平台类型根据枚举查看:%ld",(unsigned long)user.platformType);
        NSLog(@"授权就不为空:%@",user.credential);
        NSLog(@"uid:%@",user.uid);
        NSLog(@"昵称:%@",user.nickname);
        NSLog(@"图片地址:%@",user.icon);
        NSLog(@"性别:%ld",(unsigned long)user.gender);
    }];
}

#pragma mark - 其他
- (void)other {
    //判断是否授权
    [ShareSDK hasAuthorized:SSDKPlatformTypeSinaWeibo];
}

 

本文由澳门新葡亰网站所有平台发布于网址大全,转载请注明出处:网址大全:iOS第三方分享

关键词: