AppleDevice is missing in Xamarin.Forms.Labs 1.2.1-pre2

I have an iOS + PCL solution and I need to get XForms.Labs Geolocator working in my PCL but right now all calls to Resolver.Resolve() return NULL. So I'm guessing that XLabs isn't getting initialized properly. The XLabs Wiki says that a container must be setup before using XLabs services.

To test this I created new solution (unified API) with Xamarin Studio and used NuGet to install XForms 1.3.1.6296 and XForms.Labs 1.2.1-pre2. Next I copied the container setup code from XLabs Wiki into my AppDelegate class however this will not compile because AppleDevice cannot be resolved.

How can I fix this?

Here is my AppDelegate.cs

using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using UIKit;
using Xamarin.Forms.Labs.Services;
using Xamarin.Forms.Labs;

namespace UnifiedTest.iOS
{
    [Register ("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init ();

            SetIoc ();

            LoadApplication (new App ());

            return base.FinishedLaunching (app, options);
        }

        private void SetIoc()
        {
            var container = new SimpleContainer ();
            container.Register<IDevice> (t => AppleDevice.CurrentDevice);
            container.Register<IDisplay> (t => t.Resolve<IDevice> ().Display);
            container.Register<INetwork>(t=> t.Resolve<IDevice>().Network);

            Resolver.SetResolver (container.GetResolver ());
        }
    }
}
«1

Posts

  • SKallSKall USMember ✭✭✭✭

    Labs NuGet packages do not currently support 1.3.1 (unified API). You would need to get the latest master from GitHub: https://github.com/XLabs/Xamarin-Forms-Labs

  • PaulHazlettPaulHazlett USMember ✭✭

    Oh, that's makes sense. Thanks for the help.

  • PerReitzelPerReitzel DKMember ✭✭

    Hmmm .. not for me :-(

    How do I include this master into my own project. How much do I need to include? Currently I'm only using the camera integration.

    Thanks in advance
    Per

  • SKallSKall USMember ✭✭✭✭

    @PerReitzel‌, the camera feature is in Platform so you would need to include XLabs.Core + XLabs.Platform and then XLabs.Platform.[iOS][Droid][WP8].

  • PerReitzelPerReitzel DKMember ✭✭

    Ok .. but just to get this right. So I just download your Whole master source and build the Xlabs.Core and Xlabs.Platform (+Ios, Droid and WP8) bits .. and then I include the dll's from the build folder as references in my project?

    At least this is what I've been trying but when I try to run my project/app and try to get the MediaPicker through the IMediaPicker interface (mediaPicker = DependencyService.Get();) I get a null back from that call .. both on WP and Droid

  • PerReitzelPerReitzel DKMember ✭✭

    mediaPicker = DependencyService.Get(); .. of course

  • PerReitzelPerReitzel DKMember ✭✭

    sorry .. when I post this reply the IMediaPicker between the two < and > is deleted ..

  • SKallSKall USMember ✭✭✭✭

    Add XLabs.IoC as well and set the media picker there. Platform now doesn't have Xamarin.Forms reference so it is not registered with DependencyService. Alternatively you can register it yourself with DepedencyService in the platform project(s).

  • AhmadJaberAhmadJaber SEMember
    edited January 2015

    Hi!
    For any one who needs help. Below how I solved the problem.

    1- Below code In the AppDelegate side:

    private void SetIoc () { var resolverContainer = new XLabs.Ioc.SimpleContainer (); resolverContainer.Register< XLabs.Platform.Device.IDevice> (t => AppleDevice.CurrentDevice) .Register<XLabs.Platform.Device.IDisplay> (t => t.Resolve<XLabs.Platform.Device.IDevice> ().Display) .Register<XLabs.Ioc.IDependencyContainer> (t => resolverContainer); XLabs.Ioc.Resolver.SetResolver (resolverContainer.GetResolver ()); }

    2- Below Code in the implementation side (The shared library)

    var device = XLabs.Ioc.Resolver.Resolve<XLabs.Platform.Device.IDevice>(); mediaPicker = DependencyService.Get<XLabs.Platform.Services.Media.IMediaPicker> () ?? device.MediaPicker;

    PS! This solution is only for the MediaPicker

  • PerReitzelPerReitzel DKMember ✭✭

    Thanks a lot Sami & Ahmad .. and now it works Again :-)

    Sami .. when do you expect that we can download the first XLab pre .. and even better the final v. 2?

  • PerReitzelPerReitzel DKMember ✭✭

    .. and then still a problem with Android :-(

    Everything seems to be intialized well .. but when I access the camera I get the following runtime error:

    Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

    I've been trying to set this flag different Places in my code but without luck. Where and how do I solve this?

    Thanks in advance
    Per

  • rmarinhormarinho PTMember, Insider, Beta Xamurai

    In the new packages the user should call DependecyService.Register if he wants to register a Service from XLabs to be used with Xamarin Forms.

  • PerReitzelPerReitzel DKMember ✭✭

    I'm a bit newbie to this .. sorry. Can you tell me where a set this? To get my 'mediaPicker' I have this code:

            var device = Resolver.Resolve<IDevice>();
            mediaPicker = DependencyService.Get<IMediaPicker>() ?? device.MediaPicker;
    

    Thanks in advance
    Per

  • SKallSKall USMember ✭✭✭✭

    @PerReitzel‌, XLabs2.0-pre6 is in Nuget now.

    Here is the Wiki on getting IOC setup: https://github.com/XLabs/Xamarin-Forms-Labs/wiki/IOC

  • PerReitzelPerReitzel DKMember ✭✭

    Thanks Sami.

    I'm still having problem with my Android project. It works perfectly fine with WP and Ios but when running on Android I get this runtime error:

    Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag

    What I did was to first remove the references to the XLab dll's I build from the shared source. Then I install the Xlabs2.0-pre7

    From OnCreate I call the following:

        private void SetIoc()
        {
            var resolverContainer = new XLabs.Ioc.SimpleContainer();
    
            var app = new XFormsAppDroid();
    
            app.Init(this);
    
            resolverContainer.Register<IDevice>(t => AndroidDevice.CurrentDevice)
                .Register<IDisplay>(t => t.Resolve<IDevice>().Display)
                .Register<IDependencyContainer>(resolverContainer)
                .Register<XLabs.Platform.Mvvm.IXFormsApp>(app);
    
            Resolver.SetResolver(resolverContainer.GetResolver());
        }
    

    From where I have the implementation to the camera I setup the interface like this:

            var device = Resolver.Resolve<IDevice>();
            mediaPicker = DependencyService.Get<IMediaPicker>() ?? device.MediaPicker;
    

    I can see when debugging that the mediaPicker is created after the above .. but I still get the Runtime error. Any idea what it can be?

    /per

  • rmarinhormarinho PTMember, Insider, Beta Xamurai

    You will need to register the service now using DependecyService.Register() on your platform project.

  • SKallSKall USMember ✭✭✭✭

    It's a bug on the media picker due to the refactoring. I will push in a fix.

  • PerReitzelPerReitzel DKMember ✭✭

    Hi Sami,

    Thanks for helping on this!

    I just installed the Pre8 version of XLabs packages (I guess that this version include your bug fix?) .. but now I have a problem getting the Mvvm from XLabs.Platform .. it is not included as I see it?

    /per

  • PerReitzelPerReitzel DKMember ✭✭

    @SKall‌ .. when I try to download your lates XLabs source and build the references, and include the same dll's as come with the Nuget packages I installed - then everything works perfectly .. and now also with camera on my Android :smile:

    Thanks

  • XamarinSnobXamarinSnob USUniversity ✭✭

    When will Unified API support be available via Nuget?

  • SKallSKall USMember ✭✭✭✭

    @XamarinSnob‌ the pre-release is available now. The name of the packages has changed and you should search for XLabs instead of Xamarin.Forms.Labs. To get the XF add-ons install XLabs.Forms package (on iOS you probably want to add XLabs.Ioc as well since it isn't an automatic dependency like on Droid & WP).

  • MattButlerMattButler USUniversity ✭✭

    @SKall, just a FYI, I've been able to use the pre-release nuget with one exception. There isn't a nuget that includes the XLabs.Platform.DLL. I've had to manually reference. When I do, it all seems to be working. I'll report back if I find other issues.

  • XamarinSnobXamarinSnob USUniversity ✭✭

    What am I missing? I downloaded the latest XLab packages but now getting:

    "The name AppleDevice does not exist in current context".

    It's supposed to be part of the XLabs.Platforms.Device namespace but doesn't seem to be there.

    Does anybody have any ideas?

  • SKallSKall USMember ✭✭✭✭

    Nuget package configuration issues... Update to the latest and everything should be fixed now.

  • XamarinSnobXamarinSnob USUniversity ✭✭
    edited January 2015

    Still having the same problem.

    Steps taken:
    1) removed all references to Xamarin.Forms.Labs
    2) removed all references to Xamarin.Forms
    3) Installed "XLabs - Platform 2.0.0-pre91" which very conveniently includes all dependancies ;)
    4) updated namespacing all over the show and some minor refactoring

    But still I'm getting a build error (The name AppleDevice does not exist in current context) on AppleDevide.CurrentDevice on the resolver initialization here:

    var resolverContainer = new SimpleContainer();
    
    resolverContainer.Register<IDevice>(t => AppleDevice.CurrentDevice)
                                .Register<IDisplay>(t => t.Resolve<IDevice>().Display)
                                .Register<IDependencyContainer>(resolverContainer);
    

    Thanks for the help so far @SKall

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭
    edited January 2015

    @XamarinSnob‌ I had the same problem that IDevice was missing. You can fix that when you add the XLabs.Platform.dll to the Android and iOS project.
    To make things clear and XLabs working you need these dll's in your platform projects.

    XLabs.Core.dll
    XLabs.Forms.dll
    XLabs.Forms.Droid.dll or XLabs.Forms.iOS.dll
    XLabs.IoC.dll
    XLabs.Platform.dll <-- this one was missing
    XLabs.Platform.Droid.dll or XLabs.Platform.iOS.dll
    XLabs.Serialization.dll
    

    //Edit: Ok, I tried the pre91 and it installs all dependencies correctly. Does your AppDelegate inherit from XFormsApplicationDelegate?

  • XamarinSnobXamarinSnob USUniversity ✭✭
    edited January 2015

    Ahh ha! Thanks. That seems to have got me over the hurdle. I have a different issue now:

    I'm getting a strange "Could not load type 'Android.OS.BaseBundle' from assembly 'XLabs.Platform.Droid'" when I try to invoke the SelectPhotoAsync method on the mediaPicker. I'm creating the media picker as suggested above:

    var device = XLabs.Ioc.Resolver.Resolve<XLabs.Platform.Device.IDevice>();
    IMediaPicker mediaPicker = DependencyService.Get<XLabs.Platform.Services.Media.IMediaPicker>() ?? device.MediaPicker;
    

    Am I missing an assembly somewhere again?

  • XamarinSnobXamarinSnob USUniversity ✭✭

    @RaphaelSchindler‌ your solution worked, but now having issues with the media picker on android

  • XamarinSnobXamarinSnob USUniversity ✭✭

    I can't shake this bug:

    System.TypeLoadException: Could not load type 'Android.OS.BaseBundle' from assembly 'XLabs.Platform.Droid'

    Any help will be hugely appreciated ;)

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭
    edited January 2015

    @XamarinSnob‌ Take a look at this. https://github.com/XLabs/Xamarin-Forms-Labs/issues/584
    And try this in your MainActivity.cs / AppDelegate

    .Register<IMediaPicker>(t => t.Resolve<MediaPicker>())
    

    and in the shared code you use

    var mediaPicker = Resolver.Resolve<IMediaPicker>();

    this should solve your problem.

  • KimNieblingKimNiebling DKMember ✭✭

    Just tested with XLabs - Forms (v2.0.0-pre91) from NuGet which works fine with:
    container.Register<IDevice>(t => AppleDevice.CurrentDevice);

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @SKall:

    I have a few dumb questions to XLabs…
    I want to have a look to xLabs.
    Therefore I have downloaded the whole Xamarin-forms-master.zip and extract it in a folder.
    From: https://github.com/XLabs/Xamarin-Forms-Labs

    I then should be able to deploy the sample-projects (XLabs.Sample.Droid / .iOS and .WP) to the devices?
    - Correct?

    I am not able to create the app.
    Various error-messages, like:
    Unexpected error - Please file a bug report at http://bugzilla.xamarin.com. Reason: System.IO.FileNotFoundException: Could not load assembly 'XLabs.Platform.Droid
    Unexpected error - Please file a bug report at http://bugzilla.xamarin.com. Reason: System.IO.FileNotFoundException: Could not load assembly 'XLabs.Forms.Droid,
    This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ....\packages\sqlite-net-wp8.3.8.5\build\windowsphone8\sqlite-net-wp8.props. M:\SW\VS_2013\Xamarin\Xlabs\Xamarin-Forms-Labs-

    => While sqlite-net-wp8.3.8.4 is installed and I’m not able to install sqlite-net-wp8.3.8.5 from nugget.-prompt (conflict with “portable-net45+win8+wp80+Monodroid10+Xamarinios10+Monotouch10”)

    And further some errors like:
    The Metafile 'M:\SW\VS_2013\Xamarin\Xlabs\Xamarin-Forms-Labs-master\build\XLabs.Platform.dll' was not found
    Further for: 'Xlabs\Xamarin-Forms-Labs-master\build\XLabs.Ioc.dll', 'Xlabs\Xamarin-Forms-Labs-master\build\XLabs.Forms.dll', 'Xlabs\Xamarin-Forms-Labs-master\build\XLabs.Forms.Charting.dll', 'Xlabs\Xamarin-Forms-Labs-master\build\XLabs.Caching.dll' and 'Xlabs\Xamarin-Forms-Labs-master\build\debug\XLabs.Core.dll'

    How to resolve these errors - do I missing something?

    I have an existing app with various existing pages.
    If I want to include XLabs in my project, e.g. for using the Popup, query the device-properties:
    Do I have to change all my existing pages or will I be able to “mix the code” (leave some pages as they are and add new pages based on XLabs)?

    Thanks for an answer and … sorry for the dumb questions…

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭
    edited January 2015

    For the errors I can't help you, but with your questions.

    Currently there are only 2 pages from XLabs. The ExtendedMasterDetailPage and the ModelPage. Most of the time you add controls from XLabs to your pages. Like Checkbox or CarouselView and you can add them to your pages as you want. Thats for the controls.

    For the Services you have to change theMainApplication.cs and AppDelegate.cs as described in this thread.

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @RaphaelSchindler‌:
    Thanks for your Feedback.
    So.. if I understand you correct, I don't have to change the app-logic and the existing pages and can easily add some controls to the existing pages.
    So I don't have to fear side effects...

    I hope, somebody can help me further with the errors..

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭
    edited January 2015

    @FredyWenger‌ No you don't have to change the logic of anything. If you just want controls, add as you want. However the services you must register them.

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @Skall:
    Can you help me with the problems to the installation (see my posing above)?

  • LuisMarquesLuisMarques GBMember, University ✭✭

    Hi Guys, after following everything that was said on this thread and others I'm still unable to make Xlabs or his older brother Xamarin.Forms.Labs 1.2.1-pre2 work on my Xamarin Forms 1.3.1.6296 PCL Project. Reading the wiki on Xlabs it all seemed very easy before the new Xamarin Forms 1.3.1 but now things seem to have changed a bit... If anyone could walk me through getting Xlabs working with the latest stable release of Xamarin Forms which I believe is this version I'm using then that would be great... I am trying to get the Camera to work cross platform to take a picture and then store that picture on Azure Blob Storage (that will be another hurdle I will have to get working for the 3 platforms)

    If I have my AppDelegate inherit from XFormsApplicationDelegate like:
    public partial class AppDelegate : XFormsApplicationDelegate

    then visual studio complains and says that XFormsApplicationDelegate could not be found.

    If I have it follow the new Xamarin Forms 1.3.1 standard like:
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate

    then I suspect XLabs won't work but couldn't validate that because following the new standard above, another error occurs. I have copied and pasted the code above in my AppDelegate class:

    private void SetIoc ()
                    {
                        var resolverContainer = new XLabs.Ioc.SimpleContainer ();
                        resolverContainer.Register< XLabs.Platform.Device.IDevice> (t => AppleDevice.CurrentDevice)
                            .Register<XLabs.Platform.Device.IDisplay> (t => t.Resolve<XLabs.Platform.Device.IDevice> ().Display)
                            .Register<XLabs.Ioc.IDependencyContainer> (t => resolverContainer);
                        XLabs.Ioc.Resolver.SetResolver (resolverContainer.GetResolver ());
                    }
    

    And Visual Studio then complains about this line:
    resolverContainer.Register<XLabs.Platform.Device.IDevice>(t => AppleDevice.CurrentDevice)

    red underlining this bit "t => AppleDevice.CurrentDevice" stating this error message: "Cannot convert lambda expression to type 'System Type' because it is not a delegate type"

    These are all of my usings:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.WindowsAzure;
    using MonoTouch.Foundation;
    using MonoTouch.UIKit;
    using Xamarin.Forms;
    using XLabs.Forms;
    using XLabs.Serialization;
    using XLabs.Platform;
    using XLabs.Ioc;
    using XLabs.Platform.Device;
    using XLabs.Platform.Services;
    using XLabs;

    These are my Nuget prerelease Xlabs Packages:
    Xlabs - Core, Forms, IoC Unity, loC, Platform, Serialization

    By the way - When I tried to make the same code work with Xamarin.Forms.Labs 1.2.1-pre2 it would also not work because when I tried this line (or its equivalent for Xamarin.Forms.Labs - can't remember which): public partial class AppDelegate : XFormsApplicationDelegate

    Then VS complained about LoadApplication(new App()); stating that LoadApplication didn't exist...

    I spent several hours yesterday with both Xamarin.Forms.Labs and XLabs and I'm either doing something very silly or its not a peace of cake getting XLabs to work with the latest Xamarin Forms 1.3.1...

    Please Help :-)

  • I get the same errors as LuisMarques... How we can solve them?

    I think that the problem is that nuget packages are older than master packages and wiki. But I don't understand how to use master version downloaded by github.

    Thanks in advance,
    Fabio

  • LuisMarquesLuisMarques GBMember, University ✭✭

    Fabio, hopefully one of the knowledgeable people in this thread will notice our pleads for help in the next day or so :smile:
    Let me know if you fix it. I haven't had the time yet to go back to it since the weekend...

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    @LuisMarques @FabioMarcone Ok. Let us tear this down. Which Nuget do you use? Is it correctly installed in the PCL and the Platform Project?

Sign In or Register to comment.