I was hunting this down for a while with mix/various results. Tested it today and Got both to successfully work in the latest update of ios (9.3) and Android. This activates your mobile messenger app and pre-fills out the mobile Number, and body fields. Hope it helps! If you have different methods, please provide your input. Cheers! //Method-1 Code (CSharp): string mobile_num = "Your_Number"; string message ="This is a test from Unity"; #if UNITY_ANDROID string URL = string.Format("sms:{0}?body={1}",mobile_num,message); #endif #if UNITY_IOS string URL = string.Format("sms:{0}?&body={1}",mobile_num,WWW.EscapeURL(message)); #endif //Execute Text Message Application.OpenURL(URL); //Method 2 This ios version worked to - Code (CSharp): #if UNITY_IOS string URL = string.Format("sms:{0}&body={1}",mobile_num,WWW.EscapeURL(message)); #endif
Here's an update. So In order for ios and android to work properly it must be encoded, and WWW.Escape isn't a good method to encode. It encode's spaces in your string with "+" and they show up in the body of the text message. Instead use System.Uri.EscapeDataString(Your_String) which properly does it. Here's an updated version of what truly works. Tested in ios 9.3 with xcode 7.3, and android 6 - Marshmallow. Code (CSharp): string mobile_num = "Your_Number"; string message = "This is a test from Unity *^#$#$((*&& Test Symbols"; #if UNITY_ANDROID //Android SMS URL - doesn't require encoding for sms call to work string URL = string.Format("sms:{0}?body={1}",mobile_num,System.Uri.EscapeDataString(message)); #endif #if UNITY_IOS //ios SMS URL - ios requires encoding for sms call to work //string URL = string.Format("sms:{0}?&body={1}",mobile_num,WWW.EscapeURL(message)); //Method1 - Works but puts "+" for spaces //string URL ="sms:"+mobile_num+"?&body="+WWW.EscapeURL(message); //Method2 - Works but puts "+" for spaces //string URL = string.Format("sms:{0}?&body={1}",mobile_num,System.Uri.EscapeDataString(message)); //Method3 - Works perfect string URL ="sms:"+mobile_num+"?&body="+ System.Uri.EscapeDataString(message); //Method4 - Works perfectly #endif //Execute Text Message Application.OpenURL(URL);
@iwunu - I'm not completely sure. I don't have a windows phone to test. You may want to test either method (ios/android) and remove the "#If PLATFORM_DECLARATION & #endif" and see which method the winphone prefers.
Tested on winphone 8.1 & 10 Windows.ApplicationModel.Chat.ChatMessage sms = new Windows.ApplicationModel.Chat.ChatMessage(); sms.Body = message; sms.Recipients.Add(mobile_num); UnityEngine.WSA.Application.InvokeOnUIThread(async () => { await Windows.ApplicationModel.Chat.ChatMessageManager.ShowComposeSmsMessageAsync(sms); }, false);
I don't understand, i have synced my Android and iphone , but i am not allowed to transfer messages between Android and iPhone,
I don't feel any difficulty, telling me how did you do ? or it could be that the device is not fully connected , maybe you need to root your phone device ,
Can anyone help me?? i am making a app in which we receive an OTP and i want to get that it automatically filled in my app.
Anyone figured out how to add a file attachment using this? I want to send an animated gif as a text message (MMS).
Is there a way to send the message without adding a phone number? I want the player to choose who to send the text to after they click the button. the code your showing works, but when I choose a person to send the text to the body is blank.
my problem is if messages is open then the code works perfectly. but if messages is closed then the messages app opens but it goes to the home page and my body message is erased.