• iOS


    1. 把要分享的内容放入一个Array中

    NSMutableArray *activityItems = [NSMutableArray array];
    UIImage *imageItem = [UIImage imageNamed:@"YOUR_IMAGE"];
    NSString *textItem = @"YOUR_TEXT";
    NSURL *urlItem = [NSURL URLWithString:@"YOUR_URL"];
    
    [activityItems addObject:imageItem];
    [activityItems addObject:textItem];
    [activityItems addObject:urlItem];

    2. 使用这个Array初始化UIActivityViewController,并显示分享页面

    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    UIActivityViewControllerCompletionHandler activityBlock = ^(NSString *activityType, BOOL completed) {
      [activityViewController dismissViewControllerAnimated:YES completion:nil];
    };
    activityViewController.completionHandler = activityBlock;
    [self presentViewController:activityViewController animated:YES completion:nil];

    OK.

    分享页面包含的APP会根据你所分享的内容的数据类型,自动显示(有些APP要在分享界面的"More"按钮里手动开启)。

    如果要限制分享页面上显示的APP,可在present activityViewController之前再给它赋一个excludedActivityTypes属性值

    NSArray *excludeActivities = @[UIActivityTypeAirDrop,
                                   UIActivityTypePrint,
                                   UIActivityTypeAssignToContact,
                                   UIActivityTypeSaveToCameraRoll,
                                   UIActivityTypeAddToReadingList,
                                   UIActivityTypePostToFlickr,
                                   UIActivityTypePostToVimeo];
     
    activityViewController.excludedActivityTypes = excludeActivities;

    参考(需FQ):http://www.codingexplorer.com/add-sharing-to-your-app-via-uiactivityviewcontroller/

  • 相关阅读:
    java.lang.IllegalArgumentException
    JDBC概述
    IntelliJ IDEA15导入jar包
    mySQL基础
    javascript基础
    css基础
    html笔记
    关于intelliJ idea创建servlet提示cannot resolve symbol‘servlet’的问题
    IntelliJ IDEA新建JAVA WEB项目(转载)
    winform 子报表数据源赋值
  • 原文地址:https://www.cnblogs.com/staRR-k2/p/5105941.html
Copyright © 2020-2023  润新知