系統(tǒng)分享(Obj-C)

1.導(dǎo)入頭文件

#import <Social/Social.h>

2.演示效果,點(diǎn)擊屏幕的時(shí)候,彈出分享(新浪微博)

// 點(diǎn)擊屏幕,分享到新浪微博
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    // 1.創(chuàng)建控制器
    SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
    
    // 2.modal展示
    [self presentViewController:composeVc animated:YES completion:nil];
}
default.png

系統(tǒng)提供的分享方式比較少,serviceType:

NSString *const SLServiceTypeFacebook;
NSString *const SLServiceTypeTwitter;
NSString *const SLServiceTypeSinaWeibo;
NSString *const SLServiceTypeTencentWeibo;

使用系統(tǒng)分享功能控制臺(tái)可能會(huì)出現(xiàn)提示:plugin com.apple.share.SinaWeibo.post invalidated,忽略即可

還可以設(shè)置缺省文字、圖片和Url:

    // 2.1 設(shè)置圖片
    [composeVc addImage:[UIImage imageNamed:@"girl"]];
    // 2.2 設(shè)置Url
    [composeVc addURL:[NSURL URLWithString:@"http://www.itdecent.cn/users/5ec5747435a2/latest_articles"]];
    // 2.3 設(shè)置缺省文字
    [composeVc setInitialText:@"InitialText:"];

效果:

set_properties.png

完整演示代碼:

#import "ViewController.h"
#import <Social/Social.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    

}

// 點(diǎn)擊屏幕,分享到新浪微博
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    
    // 1.創(chuàng)建控制器
    SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
    
    // 2.設(shè)置屬性
    
    // 2.1 設(shè)置圖片
    [composeVc addImage:[UIImage imageNamed:@"girl"]];
    // 2.2 設(shè)置Url
    [composeVc addURL:[NSURL URLWithString:@"http://www.itdecent.cn/users/5ec5747435a2/latest_articles"]];
    // 2.3 設(shè)置缺省文字
    [composeVc setInitialText:@"InitialText:"];
    
    // 3.modal展示
    [self presentViewController:composeVc animated:YES completion:nil];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容