从React Native集成Native SMS

时间:2018-08-20 11:20:29

标签: ios react-native sms

我正在尝试从React Native集成本机SMS文本功能。进行本机集成的原因是,当前没有React Native解决方案(如react-native-sms或react-native-communications)支持将图像作为附件发送。

我有从React Native到iOS的通话,但在iOS端,我收到以下消息:

Warning: Attempt to present <MFMessageComposeViewController: 0x10e86ba00> on <FooAppModule: 0x10de097e0> whose view is not in the window hierarchy!

我的期望是MFMessageComposeViewController将与从React Native应用程序发送的文本和图像一起显示,并允许用户按下send。 iOS中的当前代码块如下所示:

@objc(FooAppModule)
class FooAppModule: UIViewController, 
MFMessageComposeViewControllerDelegate {

  var bridge: RCTBridge!
  var promiseRejectBlock: RCTPromiseRejectBlock!

   // Indicate whether or not a text message can be sent from the member's iOS device
  func canSendText() -> Bool {
    return MFMessageComposeViewController.canSendText()
  }

  // Configures and returns a MFMessageComposeViewController instance
  func configuredMessageComposeViewController(phoneNumber: String) {
    debugPrint("Phone number to be sent a text to", phoneNumber)

    let textMessageRecipients = [ phoneNumber ]

    let messageComposeVC = MFMessageComposeViewController()
    messageComposeVC.messageComposeDelegate = self  //  Make sure to set this property to self, so that the controller can be dismissed!
    messageComposeVC.recipients = textMessageRecipients
    messageComposeVC.body =  "Sending Text Message through SMS in Swift"

    self.present(messageComposeVC, animated: true, completion: nil)
  }

  // MFMessageComposeViewControllerDelegate callback - dismisses the view controller when the user is finished with it
  func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) 
  {
    controller.dismiss(animated: true, completion: nil)
  }

  @objc func shareText(_ phoneNumber: String, imageBase64: String,
               resolver resolve: @escaping RCTPromiseResolveBlock,
               rejecter reject: @escaping RCTPromiseRejectBlock) -> Void     {
        if (canSendText()) {
          configuredMessageComposeViewController(phoneNumber: phoneNumber)
    }
  }
}

我错过了哪一个难题?

0 个答案:

没有答案