What's the best approach to sharing code using Parse SDK on iOS/Android?

JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

I'm curious as to what the best approach would be to maximize the amount of shared code using the Parse SDK or Parse REST API. I'm thinking that a Core project with file linking using the Parse SDK(Which is polished), or using a Core via PCL using the Parse REST API(Implementing the API...)

Any opinions would be greatly appreciated!

Posts

  • EdSniderEdSnider USInsider, University, Developer Group Leader ✭✭

    Doesn't the Parse .NET SDK support Xamarin.Android/iOS (I'm assuming via PCL compatibility)? If so, I'd recommend the PCL core library approach over file linking.

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    I don't believe the Parse .NET SDK is PCL compat quite yet.

  • EdSniderEdSnider USInsider, University, Developer Group Leader ✭✭

    Have you checked out Parse's Xamarin component?

  • EdSniderEdSnider USInsider, University, Developer Group Leader ✭✭

    The Parse Xamarin SDK (https://www.parse.com/docs/downloads/) seems to work in a PCL. I'm guessing this is probably the same thing that comes with the Xamarin component.

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    The component seems to be the same as the respective downloads from the parse.com site. How are you adding it to a PCL? I added main Parse/Parse.NET dlls to the PCL project and added iOS and Android respectfully. When trying to run a simple snippet, it will not run from a PCL, but only from the respective platform.

  • EdSniderEdSnider USInsider, University, Developer Group Leader ✭✭

    I just added the Parse.Android.dll (from the v1.2.14 .zip download) to the PCL (Profile78).

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    Won't that crash on iOS though? Since they use different versions of threading?

  • EdSniderEdSnider USInsider, University, Developer Group Leader ✭✭

    So actually all you need is the Parse.dll in your PCL and it will run fine but you'll need to reference the platform specific assembly (Parse.Android.dll or Parse.iOS.dll) in the respective platform projects. You only need to call the ParseClient.Initialize() from the platform specific project in the correct place (e.g., in the AppDelegate constructor in iOS) and then you should be able to use the SDK from the PCL.

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    I believe I tried that, and when testing a simple query, it would say that it was not initialized, even though it would initialize on the respective platforms first (App.cs in Android or AppDelegate.cs in iOS).

    I'll try it again and let you know. Thanks for your help thus far!

  • FlynnWillifordFlynnWilliford USMember

    So Jon, did you ever get this to work for you? I'm trying to do the same thing and getting the same not initialized error.

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    Yeah there's a couple methods you can do it.

    1. Just have it in a regular class library that you file link with(Using the Parse nuget package is fine)

    2. Do it the PCL way, but will end up duplicating a bit of logic(Since have to do implementations for both Android/iOS)

    I followed an example similar to Craig Dunn's https://github.com/conceptdev/xamarin-samples/tree/master/NDCCloud

  • DavidTavarezDavidTavarez DOMember ✭✭✭

    Any example?

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    Look at the parse example in the post above. Or just file link a class library with parse logic.

  • KMullinsKMullins USMember, Xamarin Team Xamurai

    Jon,

    You could also use the new Shared Project type of project to include your Parse data access logic and simply include a reference to the shared project and the Parse platform specific .DLLs in both your Android and iOS apps.

    For more information check out our Shared Project Guide.

    Kevin

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    Glad you found it useful from our talk on Facebook!

  • AnthonyTietjenAnthonyTietjen USMember ✭✭
    edited May 2015

    Xamarin.Forms?

    I'm having trouble adding shared Parse code to a Xamarin.Forms app for iOS and Android. Can any one point me in a good direction?

    -- Update --
    The Forms PCL that was created for me by default didn't have the option of adding References. I created a new Forms PCL and this one has that option. I also created a portable class library and added parse to it using NuGet. Then I built that library and added a reference to the DLL in my Forms PCL. Looks like I am on my way...

  • SpencerSmithSpencerSmith USMember

    @JonDouglas said:
    Yeah there's a couple methods you can do it.

    1. Just have it in a regular class library that you file link with(Using the Parse nuget package is fine)

    2. Do it the PCL way, but will end up duplicating a bit of logic(Since have to do implementations for both Android/iOS)

    I followed an example similar to Craig Dunn's https://github.com/conceptdev/xamarin-samples/tree/master/NDCCloud

    @JonDouglas So you're saying that you don't use a PCL? You just share all of your Parse and other code from a regular class library? Or do you use a Shared Project?

  • MollyMcGrealMollyMcGreal USMember

    I'm interested in the answer to that last question @JonDouglas @SpencerSmith. I'm implementing Parse and Microsoft Azure (using Facebook for user authentication) and I would prefer not to do it separately whenever possible. Are you saying you didn't use a PCL?

    Also any examples like this (not in Xamarin.Forms) would be MOST appreciated.

  • DjooleeanDjooleean FRMember

    Hi all,
    As I'm just starting to use Parse for my app (a classical Xamarin Forms for iOS and Android app), I share with you my 'solution'.
    It's not a perfect solution but clean enough for me. I used conditional build and build configurations to manage the Parse for SDK problem.

    The goal is to reference the correct Parse dll (Parse.iOS.dll or Parse.Android.dll) during the build process. No need to use shared code. The project structure remains clean. This is done by using conditional references in your Xamarin Forms project (*.csproj).

    For those who are interested, I have written a detailed post about this subject here: https://kampeki-factory.blogspot.fr/2017/05/parse-for-xamarin-forms-no-pcl-my.html

Sign In or Register to comment.