So today, let's explain the functions of social sharing and the third-party sharing platform to the students! So let's not talk nonsense and go to the code!
//
// ZZViewController.h
// 04- Social sharing (iOS built- in)
//
// Created by 周昭 on 2017/3/16.
// Copyright © 2017年 ZZ. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ZZViewController : UIViewController
@end
//
// ZZViewController.m
// 04- Social sharing (iOS built- in)
//
// Created by 周昭 on 2017/3/16.
// Copyright © 2017年 ZZ. All rights reserved.
//
#import "ZZViewController.h"
#import <Social/Social.h>
@interfaceZZViewController ()
@end
@implementation ZZViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// 1. Determine if the platform is available
if (![SLComposeViewControllerisAvailableForServiceType:SLServiceTypeSinaWeibo]) {
NSLog ( @" Check if you have set up a Sina Weibo account , setting interface --> Sina Weibo --> Configure account " );
}
// 2. Create SLComposeViewController
SLComposeViewController *composeVc = [ SLComposeViewControllercomposeViewControllerForServiceType : SLServiceTypeSinaWeibo ];
// 2.1. Add share text
[composeVc setInitialText : @" If you don't have dreams , what's the difference with salted fish " ];
// 2.2. Add a shared image
[composeVc addImage:[UIImageimageNamed:@"zhouxingxing"]];
// 3.弹出分享界面
[selfpresentViewController:composeVcanimated:YEScompletion:nil];
// 4.监听点击的按钮
composeVc.completionHandler = ^ (SLComposeViewControllerResult result) {
if (result ==SLComposeViewControllerResultCancelled) {// 点击取消
} else {// 点去分享
}
};
}
@end