iOS social sharing (Apple's own)

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!

1> WeChat - the only software in China without a PC prototype
Sina Weibo - Apple integrated in iOS6
Tencent Weibo - Apple integrated in iOS7

2> There are many ways to implement social sharing in iOS
Write your own shared code for each platform (more code)
Utilize the Social.framework that comes with iOS
Leverage third-party sharing frameworks
(Baidu also has a "social login component"):  http://developer.baidu.com/wiki/index.php?title=docs/social



//

// 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





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325767097&siteId=291194637