Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been focusing on how to best share code between Android and iOS these past couple of weeks and here are my suggestions based on my experiences:</p> <p>a) In general, you can share anything between platforms that is not platform specific. </p> <p>I tend to use presenters or mediators that hold a reference to a view that is defined by an interface. For example, if I had a Login View, I would have my iOS UIViewController and my Android Activity both implement an ILoginView interface. This interface would have the following defined:</p> <ul> <li>Getters for Username and Password</li> <li>An event called LoginSubmitted</li> <li>Two methods ShowLoginFailed and GoNextScreen</li> </ul> <p>The presenter/mediator would be responsible for listening to the login being submitted, get the username/password, and passing those things off to a service call or command. Whenever the mediator received the results of the command/service it would then be responsible for invoking either ShowLoginFailed or GoNextScreen.</p> <p>I have also used interfaces for defining my SQLite Manager (<a href="https://github.com/praeclarum/sqlite-net/tree/master/src" rel="nofollow noreferrer">https://github.com/praeclarum/sqlite-net/tree/master/src</a>) , or a delegate that is responsible for making the actual web API service call. I've found I've had to do this because there is some platform specific compiling that needs to happen for the SQLite manager and RestSharp.</p> <p>Long story short, interfaces are your friend especially when you couple them with some sort of Dependency Injection system.</p> <p>b) If you are wanting your user to be prompted with an alarm when their device is in sleep mode or when they are in another app, I'd use AlarmManager for Android and LocalNotification for iOS. </p> <p>c) You can kind of sort of use PCLs with Xamarin.Android and Xamarin.iOS. The problem is that PCLs are not 100% supported yet. However, there are some tweaks you can make to your dev environment that should hopefully get you where you want:</p> <ul> <li><p>Switch to the Beta or Alpha channel in Xamarin Studio: "Xamarin Studio" -> "Check for Updates" -> Change the channel in the combo box in the upper left of the dialog box that pops up -> Select "Restart and Install Updates." This will let you have both Android and iOS projects be able to link to the same PCL in the same solution.</p></li> <li><p>After updating XS, close XS and follow the instructions in this post to modify your Mono install so PCLs properly compile: <a href="https://stackoverflow.com/questions/12041290/monodevelop-is-it-possible-to-switch-pcls-compiler/12062589#12062589">MonoDevelop: is it possible to switch PCL&#39;s compiler?</a></p></li> <li><p>To get code hinting to play nicer inside your PCL project, you'll need to grab the mscorlib.dll from your Mono install and place it in a DLLs folder in your project directory and add a reference to it in your PCL project. You can find the dll here: /Library/Frameworks/Mono.framework/Versions/3.0.10/lib/mono/4.0</p></li> </ul> <p>Once you have done all of that, you should be in pretty good shape getting your PCL to work. I've found that this has been worth the extra work in that I can now create a Unit Test project in XS link it to the PCL and run tests from within the IDE. In addition, I can use libs like Moq to mock my views and do integration tests.</p> <p>Xamarin is promising that full PCL support will be coming "soon" and we won't have to bother with these hacks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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