美文网首页
swift发短信

swift发短信

作者: 苹果上的小豌豆 | 来源:发表于2018-08-08 10:53 被阅读0次

import MessageUI

// MARK: - composeMail

    privatefunccomposeMail(){

        guard MFMessageComposeViewController.canSendText() else {

            print("不能发送短信")

            return

        }

        let messageVC = MFMessageComposeViewController()

        messageVC.messageComposeDelegate = self // 代理

        messageVC.recipients= ["18346400992"]// 收件人

        messageVC.body="美好生活"// 内容

        // 发送主题

        if MFMessageComposeViewController.canSendSubject() {

            messageVC.subject="年"

        }

        // 发送附件

        if MFMessageComposeViewController.canSendAttachments() {

            // 路径添加

            ifletpath =Bundle.main.path(forResource:"Info", ofType:"plist") {

                messageVC.addAttachmentURL(URL(fileURLWithPath: path), withAlternateFilename:"Info.plist")

            }

            // NSData添加

            if MFMessageComposeViewController.isSupportedAttachmentUTI("public.png") {

                // See [Uniform Type Identifiers Reference](https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Introduction/Introduction.html)

                ifletimage =UIImage(named:"bottom_logo") {

                    ifletdata =UIImagePNGRepresentation(image) {

                        // 添加文件

                        messageVC.addAttachmentData(data, typeIdentifier:"public.png", filename:"bottom_logo.png")

                    }

                }

            }

        }

        // messageVC.disableUserAttachments() // 禁用添加附件按钮

        self.present(messageVC, animated:true, completion:nil)

    }

    // MARK: - MFMessageComposeViewControllerDelegate

    funcmessageComposeViewController(_controller:MFMessageComposeViewController, didFinishWith result:MessageComposeResult) {

        print(controller.attachmentsasAny)// 所有附件

        // 关闭MFMessageComposeViewController

        controller.dismiss(animated:true, completion:nil)

        switchresult {// 发送状态

        caseMessageComposeResult.cancelled:

            print("Result: Mail sending cancelled") // 取消发送

        caseMessageComposeResult.sent:// 发送成功

            print("Result: Mail sent")

        caseMessageComposeResult.failed:// 发送失败

            print("Result: Message sending failed")

        }

    }

相关文章

  • swift发短信

    import MessageUI // MARK: - composeMail privatefunccomp...

  • Swift3.0 中实现发短信功能

    公司项目中要用到点击按钮发短信的功能,由于之前没做过,在网上找了一些 demo, 自己总结点,大神勿喷 - **要...

  • 最近要做的几件事情。

    几件事情: (1)、寄快递,给罗总发短信,给肖老师发短信,给姚哥发短信,给辉哥发短信,给崔杨发短信,给朱总发短信,...

  • iOS手机打电话、发短信功能

    一、实现发短信功能 1、发短信需要遵守导入框架并协议 2、在需要发短信的方法中调用下面代码 3、实现发短信的方法 ...

  • 发短信

  • 发短信

    手把手教你用python发送短消息(基于阿里云平台)

  • 香港信息

    通信:2)短信服务厅:办理,发短信BLHKRTC到10086;取消,发短信QXHKRTC到10086;查询,发短信...

  • iApp利用sit直接拨打电话和发短信

    1、直接拨打电话 2、直接发短信<由于防止恶意发短信不提供直接发短信方法> 3.调用Java直接发送短信 --调用...

  • 我教父亲用微信

    周末回家,父亲说他的手机不能发短信了,让我教教他发短信。 我教会了父亲发短信,他高兴地开始实验。看到这么...

  • iOS-发短信

    在APP内如何发短信呢? MFMessageComposeViewController这个类提供了发短信的功能。 例子

网友评论

      本文标题:swift发短信

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