美文网首页
几个系统Activity 类型的API

几个系统Activity 类型的API

作者: 天蓬元帅猪八戒 | 来源:发表于2019-01-24 14:24 被阅读0次

    1.系统自带分享(UIActivityViewController)

    //分享的标题
    NSString *textToShare = @"分享的标题。";
    //分享的图片
    UIImage *imageToShare = [UIImage imageNamed:@"312.jpg"];
    //分享的url
    NSURL *urlToShare = [NSURL URLWithString:@"http://www.baidu.com"];
    //在这里呢 如果想分享图片 就把图片添加进去 文字什么的同上
    NSArray *activityItems = @[textToShare,imageToShare, urlToShare];
    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
    //不出现在活动项目
    activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];
    [self presentViewController:activityVC animated:YES completion:nil];
    // 分享之后的回调
    activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
    if (completed) {
    NSLog(@"completed");
    //分享 成功
    } else {
    NSLog(@"cancled");
    //分享 取消
    }
    };

    2.复制链接功能

    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = @"需要复制的内容";
    pasteboard.image = image;
    pasteboard.url = url;

    3.用safari打开网址

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://github.com/wslcmk"]];

    4.保存图片到相册

    UIImage *image = [UIImage imageNamed:@"wang"];
    // 存储图片到"相机胶卷"
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    // 成功保存图片到相册中, 必须调用此方法, 否则会报参数越界错误

    • (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
      }

    5.发送短信

    MFMessageComposeViewController *messageComposeViewController = [[MFMessageComposeViewController alloc] init];
    messageComposeViewController.recipients = @[@"18682499853"];//收信人
    messageComposeViewController.messageComposeDelegate = self;
    messageComposeViewController.body = @"你好,我是且行且珍惜_iOS,请多指教!";
    messageComposeViewController.subject = @"且行且珍惜_iOS";

    6.发送邮件

    MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
    [mailComposeViewController setToRecipients:@[@"mattt@nshipster•com"]];
    [mailComposeViewController setSubject:@"WSL"];
    [mailComposeViewController setMessageBody:@"Lorem ipsum dolor sit amet"
    isHTML:NO];
    if([MFMailComposeViewController canSendMail]){
    [self presentViewController:mailComposeViewController animated:YES completion:nil];
    };

    7.添加书签

    NSURL *URL = [NSURL URLWithString:@"https://github.com/wslcmk"];
    BOOL result = [[SSReadingList defaultReadingList] addReadingListItemWithURL:URL
    title:@"WSL"
    previewText:@"且行且珍惜_iOS"
    error:nil];
    if (result) {
    NSLog(@"添加书签成功");
    }

    相关文章

      网友评论

          本文标题:几个系统Activity 类型的API

          本文链接:https://www.haomeiwen.com/subject/ukigrqtx.html