Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is similar to the way MvvmCross allows users to make phone calls. </p> <p>When using this pattern:</p> <p>The ViewModel code consumes a platform independent service via an interface - e.g.:</p> <pre><code>public interface IMvxPhoneCallTask { void MakePhoneCall(string name, string number); } </code></pre> <p>consumed by</p> <pre><code> protected void MakePhoneCall(string name, string number) { var task = this.GetService&lt;IMvxPhoneCallTask&gt;(); task.MakePhoneCall(name, number); } </code></pre> <p>in <a href="https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.Core/ViewModels/BaseViewModel.cs" rel="nofollow">https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.Core/ViewModels/BaseViewModel.cs</a></p> <p>The app setup code injects the platform specific implementation for the interface - e.g:</p> <pre><code> RegisterServiceType&lt;IMvxPhoneCallTask, MvxPhoneCallTask&gt;(); </code></pre> <p>In WP7 - this uses the <code>PhoneCallTask</code> - <a href="https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/WindowsPhone/Platform/Tasks/MvxPhoneCallTask.cs" rel="nofollow">https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/WindowsPhone/Platform/Tasks/MvxPhoneCallTask.cs</a></p> <pre><code>public class MvxPhoneCallTask : MvxWindowsPhoneTask, IMvxPhoneCallTask { #region IMvxPhoneCallTask Members public void MakePhoneCall(string name, string number) { var pct = new PhoneCallTask {DisplayName = name, PhoneNumber = number}; DoWithInvalidOperationProtection(pct.Show); } #endregion } </code></pre> <p>In Droid - it uses the <code>ActionDial Intent</code> - <a href="https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/Android/Platform/Tasks/MvxPhoneCallTask.cs" rel="nofollow">https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/Android/Platform/Tasks/MvxPhoneCallTask.cs</a></p> <pre><code>public class MvxPhoneCallTask : MvxAndroidTask, IMvxPhoneCallTask { #region IMvxPhoneCallTask Members public void MakePhoneCall(string name, string number) { var phoneNumber = PhoneNumberUtils.FormatNumber(number); var newIntent = new Intent(Intent.ActionDial, Uri.Parse("tel:" + phoneNumber)); StartActivity(newIntent); } #endregion } </code></pre> <p>In Touch - it just uses Urls - <a href="https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/Touch/Platform/Tasks/MvxPhoneCallTask.cs" rel="nofollow">https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/Touch/Platform/Tasks/MvxPhoneCallTask.cs</a></p> <pre><code>public class MvxPhoneCallTask : MvxTouchTask, IMvxPhoneCallTask { #region IMvxPhoneCallTask Members public void MakePhoneCall(string name, string number) { var url = new NSUrl("tel:" + number); DoUrlOpen(url); } #endregion } </code></pre> <hr> <p>In the vnext version of mvvmcross, this approach is further formalized using plugins - see a brief introduction to these in the 'going portable' presentation at <a href="http://slodge.blogspot.co.uk/2012/06/mvvm-mvvmcross-monodroid-monotouch-wp7.html" rel="nofollow">http://slodge.blogspot.co.uk/2012/06/mvvm-mvvmcross-monodroid-monotouch-wp7.html</a></p> <p>For example, in vNext the phone call code above is contained in the PhoneCall plugin - <a href="https://github.com/slodge/MvvmCross/tree/vnext/Cirrious/Plugins/PhoneCall" rel="nofollow">https://github.com/slodge/MvvmCross/tree/vnext/Cirrious/Plugins/PhoneCall</a></p> <hr> <p>One of the challenges of your task may be the word "any" - differences in platform implementation might make it hard to define a cross-platform interface that works across all the platforms for any one of NFC, Bluetooth, etc, let alone all of them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload