0

アプリケーションメッセージを数回上げて、複数のテキストメッセージを送信する必要があります。しかし、コンソールには次のエラーが表示されます。

2016-08-27 19:27:17.237 AlertaTel 2.0[841:263754] Attempt to present <MFMessageComposeViewController: 0x15e19ba00> on <AlertaTel_2_0.ViewController: 0x15de43af0> which is waiting for a delayed presention of <MFMessageComposeViewController: 0x15e24ca00> to complete

この問題についてこのサイトを読みましたが、Objective-c の解決策またはトピックしか見つかりませんでした。正直なところ、言語を習得していません (私はより指向の Swfit です)。

コードを添付しました:

クラス MessageComposer

class MessageComposer: NSObject, MFMessageComposeViewControllerDelegate {

// A wrapper function to indicate whether or not a text message can be sent from the user's device
func canSendText() -> Bool {
    return MFMessageComposeViewController.canSendText()
}

// Configures and returns a MFMessageComposeViewController instance
func configuredMessageComposeViewController(unicaVariable : String) -> MFMessageComposeViewController {
    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 = "Estoy en peligro, aca esta mi última ubicación: https://maps.google.com/maps?q="+(view.locationManager.location?.coordinate.latitude.description)!+","+(view.locationManager.location?.coordinate.longitude.description)!+". "+(unicaVariable)
    //view.performRequestAndUpdateUI()
    return messageComposeVC

}

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

}

ViewController で:

 func levantarMensaje(datoWebService: String){
    if (messageComposer.canSendText()) {
        let messageComposeVC = messageComposer.configuredMessageComposeViewController(datoWebService)
        presentViewController(messageComposeVC, animated: true, completion: nil)

    } else {
        // Let the user know if his/her device isn't able to send text messages

    }
}

そして、@IBAction でこのメソッドを呼び出します。

  @IBAction func sendTextMessageButtonTapped(sender: UIButton) {
    levantarMensaje()
}

IBAction に単純な「FOR」を実装すると、上記のエラーが表示されます。

ご回答ありがとうございます。

4

1 に答える 1

2

ここで起こっていることは、前のモーダル プレゼンテーションがまだアニメーション化されている間に、モーダル プレゼンテーションを開始しようとしているということです。UIKit はそれを好みません。次のプレゼンテーションを開始する前に、1 つのプレゼンテーションが終了するまで待つ必要があります。これを行うにはいくつかの方法があります。

1 つ目は、複数のモーダル プレゼンテーションを同時に行うことですが、アニメーションが同時に発生しないようにすることです。これを行うには、次のメッセージ ビュー コントローラーを提示する引数をpresentViewController(_:, animated:, completion:)使用するように呼び出しを変更します。completionそうすれば、最初のメッセージ ビューが表示され、アニメーションが終了すると次のメッセージ ビューが開始されます。

もう 1 つは、次のメッセージを表示する前に、1 つのメッセージが送信される (またはキャンセルされる) まで待機することです。そのためcontroller.dismissViewControllerAnimated(true, completion: nil)には、上で説明したものに似たものに置き換えます。引数にnil を渡す代わりに、completionメッセージ ビューがなくなるまで、次のメッセージ ビューを表示するクロージャを渡します。

于 2016-08-28T00:08:32.830 に答える