我需要发送多条短信,多次提出应用程序消息。 但控制台显示此错误:
int x=0;
x=new A1( ).executeOnExecutor( AsyncTask.SERIAL_EXECUTOR );
(Here x is just for the sake of explanation and making it simple, take it as a pseudo code rather than actual code)
if (x==2)
new A2( ).executeOnExecutor( AsyncTask.SERIAL_EXECUTOR );
我在这个网站上看到了这个问题,但只在Objective-c中找到了解决方案或主题,老实说甚至不掌握语言(我更倾向于Swfit)。
我附上了我的代码:
Class MessageComposer
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
}
在ViewController中:
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)
}
我在@IBAction中调用此方法:
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上实现一个简单的“FOR”时,我出现的错误就出现了。
非常感谢您的回答,问候!
答案 0 :(得分:2)
这里发生的事情是,您在尝试开始模态演示时,之前的模态演示仍然是动画。 UIKit并不喜欢这样;您需要等到一个演示文稿完成后再开始下一个演示文稿。有几种方法可以做到这一点。
首先是同时进行多次模态演示,但要确保动画不会同时发生。您可以通过将调用更改为presentViewController(_:, animated:, completion:)
来使用completion
参数来显示下一个消息视图控制器。这样就会出现第一个消息视图,当它完成动画时,下一个将开始,等等。
另一个是等到一个消息被发送(或取消)之后再呈现下一个消息。为此,您将controller.dismissViewControllerAnimated(true, completion: nil)
替换为类似于上述内容的内容。不是为completion
参数传递nil,而是传递一个显示下一个消息视图的闭包,直到没有剩余。