ios - Application tried to present a nil modal view controller on target when sending text -
i'm trying sent text message , have controller set so, error message 'nsinvalidargumentexception', reason: 'application tried present nil modal view controller on target <ally.textmessagecontroller: 0x7fd5361278e0>.' i've made sure in storyboard i'm connecting textmessagecontroller i'm not quite sure causing crash.
class textmessagecontroller: uiviewcontroller, mfmessagecomposeviewcontrollerdelegate { var phone: string? override func viewdidload() { super.viewdidload() print(phone) var messagevc = mfmessagecomposeviewcontroller() messagevc.body = "hey need help, available"; messagevc.recipients = ["555555555"] messagevc.messagecomposedelegate = self; presentviewcontroller(messagevc, animated: false, completion: nil) // additional setup after loading view. } func cansendtext() -> bool { return mfmessagecomposeviewcontroller.cansendtext() } func messagecomposeviewcontroller(controller: mfmessagecomposeviewcontroller!, didfinishwithresult result: messagecomposeresult) { self.dismissviewcontrolleranimated(true, completion: nil) switch (result.rawvalue) { case messagecomposeresultcancelled.rawvalue: print("message cancelled") self.dismissviewcontrolleranimated(true, completion: nil) case messagecomposeresultfailed.rawvalue: print("message failed") self.dismissviewcontrolleranimated(true, completion: nil) case messagecomposeresultsent.rawvalue: print("message sent") self.dismissviewcontrolleranimated(true, completion: nil) default: break; } } here error message
'nsinvalidargumentexception', reason: 'application tried present nil modal view controller on target <ally.textmessagecontroller: 0x7fd5361278e0>.'
you should first check whether device can send text message , present it. instance simulator can not send text message code crash in it. along simulator, user’s device may not set delivery of messages. perform following check
if messagevc.cansendtext() { presentviewcontroller(messagevc, animated: false, completion: nil) }
Comments
Post a Comment