# 分享接口

# 1、说明

将游戏内容包括链接,图片等分享给好友或者朋友圈等。

分享根据国内海外渠道不同分为国内:QQ,微信分享;海外:facebook分享

# 2、代码调用

# 2.1、 导入头文件

#import "DHUnionConfig.h"
#import "DHUnionDelegate.h"
#import "DHUnionSDK.h"

# 2.2、 导入分享代理回调

@interface ViewController ()<DHUnionShareDelegate>

# 2.3、 分享链接

DHUnionShareLinkContent *linkContent = [[DHUnionShareLinkContent alloc] init];
    linkContent.contentURL = [NSURL URLWithString:@"https://www.baidu.com"];   //分享链接地址
    [DHUnionSDK shareFromViewController:self withContent:linkContent delegate:self];

# 2.4、 分享图片

DHUnionSharePhotoContent *photoContent = [[DHUnionSharePhotoContent alloc] init];
DHUnionSharePhoto *photo = [[DHUnionSharePhoto alloc] init];
photo.image = [UIImage imageNamed:@"imag1.png"];
photo.userGenerated = NO;
photoContent.photos = @[photo];
[DHUnionSDK shareFromViewController:self withContent:photoContent delegate:self];

# 2.5、 分享结果

#pragma mark - DHUnionShareDelegate
- (void)sharerDidCancel:(id)sharer
{
    NSLog(@"++++===%@ share did cancel",sharer);
    self.resultView.text = [NSString stringWithFormat:@"分享取消:%@",sharer];
}

- (void)sharer:(id)sharer didFailWithError:(NSError *)error
{
    NSLog(@"++++===%@ share error%@",sharer,error);
    self.resultView.text = [NSString stringWithFormat:@"分享失败:%@",error];
}

- (void)sharer:(id)sharer didCompleteWithResults:(NSDictionary *)results
{
    NSLog(@"++++===%@ share complete%@",sharer,results);
    self.resultView.text = [NSString stringWithFormat:@"分享成功:%@,\n结果%@",sharer,results];
}

Last Updated: 2024/8/30 17:47:25