问题
I have a button in my Windows Phone 8.1 RT app. When the user clicks the button, 2 SMS are supposed to be sent to two different users.
I can launch one SMS Task using the following code
var message = new ChatMessage();
message.Recipients.Add("1231233");
message.Body = "This is a text message from an app!";
await ChatMessageManager.ShowComposeSmsMessageAsync(message);
But when I do this multiple times, the app crashes. The Task complete event fires on task launch, is there a way to know if the user has returned to the app after sending SMS so the next one can be fired?
回答1:
If the ShowComposeSmsMessageAsync
is anything like the MessageDialog.ShowAsync
method, which seems true as both return IAsyncInfo objects (..Action/..Operation is different, but the async part is important for us), this problem could be solved like the problem of showing multiple message dialogs. A quick search yielded this question, with multiple correct solutions: How to allow for multiple popups at once in WinRT?
If the above doesn't work, you could - for example - subscribe to the VisibilityChanged
event of the app Window
(https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.window.aspx), as it should provide you with an event about the user returning from the sms task.
So basically 1. subscibe to event, 2. send 1st sms, 3. wait for event, 4. send 2nd sms.
来源:https://stackoverflow.com/questions/29764178/launch-2-sms-compose-tasks-in-windows-phone-8-1-rt-app