iOS 分享到第三方

39 篇文章 0 订阅

系统自带

引入Social.framework包,

#import <Social/Social.h>

-(void)sinaShare{
    //    1.判断分享类型是否可用
    if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
        NSLog(@"新浪微博不可用,请打开设置,然后配置账号");
    }

//    2.创建分享控制器
    SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];


    //分享预设图片
    [composeVC addImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://gifclub-public.stor.sinaapp.com/Uploads/gifs/57892390220b0.gif"]]]];


//    3.模态视图弹出控制器
    [self presentViewController:composeVC animated:YES completion:nil];
}

友盟分享

在下载友盟社会化SDK 时,博主建议将下面的也勾选上一同下载下来
这里写图片描述

不明白时可以参照下测试demo

获取友盟AppKey
进入友盟的官网:http://www.umeng.com/codecenter.html?spm=0.0.0.0.nHqhCG

这里写图片描述

这里写图片描述

点击管理

这里写图片描述

这里写图片描述

输入App信息,提交即可获取AppKey.

分享到新浪微博

查看友盟官方文档,根据官方文档,添加需要的系统库和配置info.plist 文件
在other linker flags增加-ObjC 选项,并添加ImageIO 系统framework(实现新浪微博必须完成的步骤)

appdelegate.m

#import "UMSocial.h"
#import "UMSocialSinaSSOHandler.h"



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

    //设置友盟社会化组件appkey
    [UMSocialData setAppKey:@"5789db8b67e58e7a48003284"];//@"5789db8b67e58e7a48003284"这一串字符便是友盟AppKey

    //打开调试log的开关
    [UMSocialData openLog:YES];

    // 打开新浪微博的SSO开关
    // 将在新浪微博注册的应用appkey、redirectURL替换下面参数,并在info.plist的URL Scheme中相应添加wb+appkey,如"wb3921700954",详情请参考官方文档。
    //博主在这使用的是友盟默认的应用appkey,secret
    [UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:@"3921700954"
                                              secret:@"04b48b094faeb16683c32669824ebdad"
                                         RedirectURL:@"http://sns.whalecloud.com/sina2/callback"];

    return YES;
}


/**
 这里处理新浪微博SSO授权之后跳转回来,和微信分享完成之后跳转回来
 */
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
}

/**
 这里处理新浪微博SSO授权进入新浪微博客户端后进入后台,再返回原来应用
 */
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [UMSocialSnsService  applicationDidBecomeActive];
}

配置URL scheme
博主使用的是友盟默认的url scheme
这里写图片描述

然后在分享按钮的调用方法中实现
调用直接分享底层接口

//这里你可以把分享平台UMShareToSina换成其他平台
    [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina] content:@"666666" image:nil location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response) {
        if (response.responseCode == UMSResponseCodeSuccess) {
//            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"成功" message:@"分享成功" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];

            UIAlertController *alertView = [UIAlertController alertControllerWithTitle:@"成功" message:@"分享成功" preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction *enterAction = [UIAlertAction actionWithTitle:@"好" style:UIAlertActionStyleDefault handler:nil];

            [alertView addAction:enterAction];

            [self presentViewController:alertView animated:YES completion:nil];

//            [alertView show];
        } else {
            UIAlertController *alertView = [UIAlertController alertControllerWithTitle:@"失败" message:@"分享失败" preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction *enterAction = [UIAlertAction actionWithTitle:@"好" style:UIAlertActionStyleDefault handler:nil];

            [alertView addAction:enterAction];

            [self presentViewController:alertView animated:YES completion:nil];
        }
    }];

其他的博主就不多写了,因为友盟的官方文档中都有说明了,就不摘抄那么多了
友盟的官方文档:http://dev.umeng.com/social/ios/quick-integration#1_5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值