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