Unity与IOS——Twitter分享SDK

这次记录一下Unity接入Twitter分享的SDK,做海外版本开发的应该都会接触到。
由于项目中使用的是XUPorter管理IOS的SDK,所以进行扩展即可。

关于UnityIOS的SDK管理方案XUPorter可以看下这个大佬的文章:
https://blog.csdn.net/u013457933/article/details/87990998

1.下载SDK:

更新一下:
https://github.com/touren/twitter-kit-ios/releases/tag/v5.2.0
上面的TwitterKit里用到了UIWebView,提审会不通过。这个老哥改出来了一个不用UIWebView的版本。

2.接下来接入:

a.在application:didFinishLaunchingWithOptions里初始化SDK,可以理解为这是IOS程序启动时候的方法,在这里初始化比较合理。
初始化方法如下:(xxxxx填入你的SDK参数)

[[Twitter sharedInstance] startWithConsumerKey:@"xxxxxxxxxxxxx" consumerSecret:@"xxxxxxxxxxxxxxxxxxx"];

b.在application:openURL:options里调用下面的方法。

[[Twitter sharedInstance] application:application openURL:url options:options];

c.提供一个extern c方法给unity调用。(Unity要调IOS代码只能这么调)

extern "C"
{
	void _share2Twitter(char* imagePath);
}

void _share2Twitter(char* imagePath)
{
	NSString *strReadAddr = [NSString stringWithUTF8String:imagePath];
    UIImage *image = [UIImage imageWithContentsOfFile:strReadAddr];
	
    if ([[Twitter sharedInstance].sessionStore hasLoggedInUsers]) {
        TWTRComposer *composer = [[TWTRComposer alloc] init];
       
        [composer setImage:image];  
        [composer showFromViewController:GetAppController().window.rootViewController completion:^(TWTRComposerResult result){
             if(result == TWTRComposerResultCancelled) {
                //success
             }else{
                //failed
             }
         }];
    } else {
        [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
            if (session) {
                 TWTRComposer *composer = [[TWTRComposer alloc] init];
                 [composer setImage:image];
                 [composer showFromViewController:GetAppController().window.rootViewController completion:^(TWTRComposerResult result){
                     if(result == TWTRComposerResultCancelled) {
                        //success
                     }else{
						//failed
                     }
                 }]; 
            } else {
            }
        }];
    }
}
3.在C#中调用分享接口。
4.Xcode注意事项:

此SDK需要SafariServices.framework和Accounts.framework,给加上

由于这个SDK的版本很乱,编译出来缺framework补上就行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值