Skip to content

iOS---分享

概述

借助宝船SDK平台接入各个平台的登录,你可以在你的应用中快速轻松地实现登录功能。

SDK平台配置和依赖导入

应用接入

1.在AppDelegate类中初始化SDK。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
       // Override point for customization after application launch.
       [BrickManager initBrickWith:@"cdshf8dfbshdf8sdfc" appSecret:@"sdjncvs889347r983274cvhsd" bindId:@"com.xxx.name"];//宝船出海SDK应用创建后,平台生成的key
       //宝船出海SDK应用创建后,平台生成的秘钥
       [BrickManager wechatRegisterAppWith:@"wxd326eceb36c332323" universalLink:@"https://weixin.com/"];
       //微信开发者ID
       //微信开发者Universal Link
       [BrickManager qqRegisterWithAppId:@"1021401435" andUniversalLink:@"https://xxx.com/qq_conn/1021401435"];
       //QQ开放者id
       //QQ开发者Universal Link
       return YES;
    }

2.配置添加CoreTelephony.framework,libc++.tbd,libsqlite3.0.tbd,libz.tbd,SystemConfiguration.framework,WebKit.framework。

bricksdkcreate10

另外如果需要Facebook分享需要配置Accelerate.framework,SwiftUI.framework。

bricksdkcreate13

3.配置URL Type。

bricksdkcreate11

4.配置Other Linker Flags。

bricksdkcreate12

用户分享相关方法和说明

用户分享

文本分享示例

    BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
    message.title = @"分享文本内容";

图片分享示例

    NSData *imageData = UIImageJPEGRepresentation(image, 0.7);
    BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
    BrickShareImageObject *imageObject = [[BrickShareImageObject alloc] init];
    imageObject.shareImage = imageData;
    imageObject.title = @"图片分享";
    imageObject.descr = @"图片分享描述";
    message.shareObject = imageObject;

视频分享示例

    UIImage *image = [UIImage imageNamed:@"icon"];
    NSData *imageData = UIImageJPEGRepresentation(image, 0.7);
    BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
    BrickShareVideoObject *videoObject = [[BrickShareVideoObject alloc] init];
    videoObject.title = @"视频分享";
    videoObject.descr = @"视频分享描述";
    videoObject.videoUrl = @"视频链接";
    videoObject.videoLowBandUrl = @"";
    videoObject.thumbImage = imageData;
    videoObject.flashURL = nil;
    message.shareObject = videoObject;

网页分享示例

    BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
    UIImage *image = [UIImage imageNamed:@"icon"];
    NSData *data = UIImageJPEGRepresentation(image, 1);
    BrickSharePlatformType type;
    if (self.sharePlatformType == 1) {
        type = BrickSharePlatformType_Wechat;
        BrickShareWebpageObject *webObject = [BrickShareWebpageObject shareObjectWithTitle:@"分享标题" description:@"分享内容描述" thumImage:[UIImage imageNamed:@"icon"]];
        webObject.webpageUrl = @"网页链接";//必传
       message.shareObject = webObject;
    } else {
       type = BrickSharePlatformType_QQ;
       BrickShareWebpageObject *webObject = [BrickShareWebpageObject shareObjectWithTitle:@"分享标题" description:@"分享内容描述" thumImage:data];
       webObject.webpageUrl = @"网页链接";//必传
       message.shareObject = webObject;
    }

音乐分享

    BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
    BrickShareMusicObject *musicObject = [[BrickShareMusicObject alloc] init];
    musicObject.title = @"歌曲名:不要说话";
    musicObject.descr = @"专辑名:不想放手歌手名:陈奕迅";
    musicObject.thumbImage = [UIImage imageNamed:@"icon"];
    musicObject.musicUrl = @"http://y.qq.com/i/song.html?songid=432451&source=mobileQQ%23wechat_redirect";
    musicObject.musicDataUrl = @"音乐数据url地址";
    musicObject.musicLowBandUrl = @"音乐lowband网页的url地址";
    musicObject.musicLowBandDataUrl = @"音乐lowband数据url地址";
    musicObject.songLyric = @"歌词信息 LRC格式";
    musicObject.songAlbumUrl = @"音乐封面图Url";
    musicObject.previewImageUrl = @"http://imgcache.qq.com/music/photo/mid_album_300/V/E/000J1pJ50cDCVE.jpg";
    musicObject.flashURL = [NSURL URLWithString:@"http://10.136.9.109/fcgi-bin/fcg_music_get_playurl.fcg?song_id=1234&redirect=0&filetype=mp3&qqmusic_fromtag=15&app_id=100311325&app_key=b233c8c2c8a0fbee4f83781b4a04c595&device_id=1234"];
    message.shareObject = musicObject;

分享调用示例

    - (IBAction)wechatShareClick:(UIButton *)sender {
        BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
        BrickShareWebpageObject *webObject = [BrickShareWebpageObject shareObjectWithTitle:@"分享标题" description:@"分享内容描述" thumImage:[UIImage imageNamed:@"icon"]];
        webObject.webpageUrl = @"https://test.com";
        message.shareObject = webObject;
        [BrickManager shareToPlatformType:BrickSharePlatformType_Wechat messageObject:message currentViewController:self success:^(BrickCompleteResult * _Nonnull completeResult) {
           BrickCompleteResult *result = completeResult;
           NSInteger code = result.code;
           NSString *message = result.message;
           NSDictionary *data = result.data;
           NSLog(@"分享成功:%ld-----%@----%@",(long)code,message,data);
        } failure:^(BrickCompleteResult * _Nonnull completeResult) {
           BrickCompleteResult *result = completeResult;
           NSInteger code = result.code;
           NSString *message = result.message;
           NSLog(@"分享失败:%ld-----%@",(long)code,message);
         }];
    }

重写AppDelegate或SceneDelegate的continueUserActivity方法: 注意:适配了SceneDelegate的App,系统将会回调SceneDelegate的continueUserActivity方法,所以需要重写SceneDelegate的该方法。

    - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url  {
        return [BrickManager brickShareHandleOpenURL:url];
    }
    

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {    
        return [BrickManager brickShareHandleOpenURL:url];
    }


    - (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
        NSArray *contextArray = [URLContexts allObjects];
        UIOpenURLContext *urlContent = [contextArray firstObject];
        [BrickManager brickShareHandleOpenURL:urlContent.URL];
    }

    - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
        [BrickManager brickShareHandleOpenUniversalLink:userActivity];
    }

Facebook分享CameraEffect示例:

    BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
    BrickShareFacebookCameraEffectContentObject *contentObject = [[BrickShareFacebookCameraEffectContentObject alloc] init];
    FBSDKCameraEffectArguments *arguments = [[FBSDKCameraEffectArguments alloc] init];
    FBSDKCameraEffectTextures *textures = [[FBSDKCameraEffectTextures alloc] init];
    FBSDKHashtag *tag = [[FBSDKHashtag alloc] initWithString:@""];
    contentObject.effectID = @"";
    contentObject.effectArguments = arguments;
    contentObject.effectTextures = textures;
    contentObject.contentURL = [NSURL URLWithString:@"https://developers.facebook.com/docs/applinks/"];
    contentObject.hashtag = tag;
    contentObject.peopleIDs = @[];
    contentObject.placeID = @"";
    contentObject.pageID = @"";
    contentObject.ref = @"";
    contentObject.mode = FBSDKShareDialogModeAutomatic;
    message.shareObject = contentObject;
    [BrickManager shareToPlatformType:BrickSharePlatformType_Facebook messageObject:message currentViewController:self success:^(BrickCompleteResult * _Nonnull completeResult) {
        BrickCompleteResult *result = completeResult;
        NSInteger code = result.code;
        NSString *message = result.message;
        NSDictionary *data = result.data;
        NSLog(@"分享成功:%ld-----%@----%@",(long)code,message,data);
    } failure:^(BrickCompleteResult * _Nonnull completeResult) {
        BrickCompleteResult *result = completeResult;
        NSInteger code = result.code;
        NSString *message = result.message;
        NSLog(@"分享失败:%ld-----%@",(long)code,message);
    }];

Facebook分享链接示例:

BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
    BrickShareFacebookLinkContentObject *contentObject = [[BrickShareFacebookLinkContentObject alloc] init];
    FBSDKHashtag *tag = [[FBSDKHashtag alloc] initWithString:@""];
    contentObject.quote = @"";
    contentObject.contentURL = [NSURL URLWithString:@"https://developers.facebook.com/docs/applinks/"];
    contentObject.hashtag = tag;
    contentObject.pageID = @"";
    contentObject.placeID = @"";
    contentObject.ref = @"";
    contentObject.peopleIDs = @[];
    contentObject.mode = FBSDKShareDialogModeAutomatic;
    message.shareObject = contentObject;
    [BrickManager shareToPlatformType:BrickSharePlatformType_Facebook messageObject:message currentViewController:self success:^(BrickCompleteResult * _Nonnull completeResult) {
        BrickCompleteResult *result = completeResult;
        NSInteger code = result.code;
        NSString *message = result.message;
        NSDictionary *data = result.data;
        NSLog(@"分享成功:%ld-----%@----%@",(long)code,message,data);
    } failure:^(BrickCompleteResult * _Nonnull completeResult) {
        BrickCompleteResult *result = completeResult;
        NSInteger code = result.code;
        NSString *message = result.message;
        NSLog(@"分享失败:%ld-----%@",(long)code,message);
    }];

Facebook分享Media示例:

UIImage *image = [UIImage imageNamed:@"icon"];
    BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
    BrickShareFacebookMediaContentObject *contentObject = [[BrickShareFacebookMediaContentObject alloc] init];
    FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] initWithImage:image isUserGenerated:YES];
    FBSDKHashtag *tag = [[FBSDKHashtag alloc] initWithString:@""];
    contentObject.media = @[photo];
    contentObject.contentURL = [NSURL URLWithString:@"https://developers.facebook.com/docs/applinks/"];
    contentObject.hashtag = tag;
    contentObject.peopleIDs = @[];
    contentObject.placeID = @"";
    contentObject.pageID = @"";
    contentObject.ref = @"";
    contentObject.mode = FBSDKShareDialogModeAutomatic;
    message.shareObject = contentObject;
    [BrickManager shareToPlatformType:BrickSharePlatformType_Facebook messageObject:message currentViewController:self success:^(BrickCompleteResult * _Nonnull completeResult) {
        BrickCompleteResult *result = completeResult;
        NSInteger code = result.code;
        NSString *message = result.message;
        NSDictionary *data = result.data;
        NSLog(@"分享成功:%ld-----%@----%@",(long)code,message,data);
    } failure:^(BrickCompleteResult * _Nonnull completeResult) {
        BrickCompleteResult *result = completeResult;
        NSInteger code = result.code;
        NSString *message = result.message;
        NSLog(@"分享失败:%ld-----%@",(long)code,message);
    }];

Facebook分享图片示例:

UIImage *image = [UIImage imageNamed:@"icon"];
    BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
    BrickShareFacebookPhotoContentObject *contentObject = [[BrickShareFacebookPhotoContentObject alloc] init];
    FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] initWithImage:image isUserGenerated:YES];
    FBSDKHashtag *tag = [[FBSDKHashtag alloc] initWithString:@""];
    contentObject.photos = @[photo];
    contentObject.hashtag = tag;
    contentObject.peopleIDs = @[];
    contentObject.placeID = @"";
    contentObject.pageID = @"";
    contentObject.ref = @"";
    contentObject.mode = FBSDKShareDialogModeAutomatic;
    message.shareObject = contentObject;
    [BrickManager shareToPlatformType:BrickSharePlatformType_Facebook messageObject:message currentViewController:self success:^(BrickCompleteResult * _Nonnull completeResult) {
        BrickCompleteResult *result = completeResult;
        NSInteger code = result.code;
        NSString *message = result.message;
        NSDictionary *data = result.data;
        NSLog(@"分享成功:%ld-----%@----%@",(long)code,message,data);
    } failure:^(BrickCompleteResult * _Nonnull completeResult) {
        BrickCompleteResult *result = completeResult;
        NSInteger code = result.code;
        NSString *message = result.message;
        NSLog(@"分享失败:%ld-----%@",(long)code,message);
    }];

Facebook分享视频示例:

UIImage *image = [UIImage imageNamed:@"icon"];
    BrickShareMessageObject *message = [BrickShareMessageObject messageObject];
    BrickShareFacebookVideoContentObject *contentObject = [[BrickShareFacebookVideoContentObject alloc] init];
    FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] initWithImage:image isUserGenerated:YES];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"111" ofType:@".mp4"];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    FBSDKShareVideo *video = [[FBSDKShareVideo alloc] initWithData:data previewPhoto:photo];
    FBSDKHashtag *tag = [[FBSDKHashtag alloc] initWithString:@""];
    contentObject.video = video;
    contentObject.hashtag = tag;
    contentObject.peopleIDs = @[];
    contentObject.placeID = @"";
    contentObject.pageID = @"";
    contentObject.ref = @"";
    contentObject.mode = FBSDKShareDialogModeAutomatic;
    message.shareObject = contentObject;
    [BrickManager shareToPlatformType:BrickSharePlatformType_Facebook messageObject:message currentViewController:self success:^(BrickCompleteResult * _Nonnull completeResult) {
        BrickCompleteResult *result = completeResult;
        NSInteger code = result.code;
        NSString *message = result.message;
        NSDictionary *data = result.data;
        NSLog(@"分享成功:%ld-----%@----%@",(long)code,message,data);
    } failure:^(BrickCompleteResult * _Nonnull completeResult) {
        BrickCompleteResult *result = completeResult;
        NSInteger code = result.code;
        NSString *message = result.message;
        NSLog(@"分享失败:%ld-----%@",(long)code,message);
    }];