iOS社交分享(苹果自带)

那么今天来给同学们讲解社交分享的功能,以及第三方分享平台!那么废话不多说直接上代码!

1> 微信 - 国内唯一一款没有PC原型的软件
新浪微博 - 苹果在iOS6集成
腾讯微博 - 苹果在iOS7集成

2> 在iOS中实现社交分享的方法很多
自己编写各个平台的分享代码(代码量较多)
利用iOS自带的Social.framework
利用第三方的分享框架
(百度还有个"社会化登录组件"):  http://developer.baidu.com/wiki/index.php?title=docs/social



//

//  ZZViewController.h

//  04-社交分享(iOS自带)

//

//  Created by 周昭 on 2017/3/16.

//  Copyright © 2017 ZZ. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface ZZViewController : UIViewController


@end


//

//  ZZViewController.m

//  04-社交分享(iOS自带)

//

//  Created by 周昭 on 2017/3/16.

//  Copyright © 2017 ZZ. All rights reserved.

//


#import "ZZViewController.h"

#import <Social/Social.h>



@interface ZZViewController ()


@end


@implementation ZZViewController


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    // 1.判断平台是否可用

    if (![SLComposeViewControllerisAvailableForServiceType:SLServiceTypeSinaWeibo]) {

        NSLog(@"查看您是否设置了新浪微博账号,设置界面-->新浪微博-->配置账号");

    }

    

    // 2.创建SLComposeViewController

    SLComposeViewController *composeVc = [SLComposeViewControllercomposeViewControllerForServiceType:SLServiceTypeSinaWeibo];

    

    // 2.1.添加分享文字

    [composeVc setInitialText:@"做人如果没有梦想,跟咸鱼有什么区别"];

    

    // 2.2.添加分享图片

    [composeVc addImage:[UIImageimageNamed:@"zhouxingxing"]];

    

    // 3.弹出分享界面

    [selfpresentViewController:composeVcanimated:YEScompletion:nil];

    

    // 4.监听点击的按钮

    composeVc.completionHandler = ^ (SLComposeViewControllerResult result) {

        if (result ==SLComposeViewControllerResultCancelled) {// 点击取消

            

        } else {// 点去分享

            

        }

    };

}



@end





猜你喜欢

转载自blog.csdn.net/zz_iosdeveloper/article/details/62892179
今日推荐