Forum Xamarin Xamarin.Forms

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

2»

Posts

  • FabioMarconeFabioMarcone USMember
    edited February 2015

    @RaphaelSchindler I use Official Nuget repository (www.nuget.org/api/v2) and I've in ios project:

    • ExifLib.PCL 1.0.0
    • Newtonsoft.Json 6.0.8
    • Xamarin.Forms 1.3.1.6296
    • Xamarin.Forms.Labs 1.2.0
    • Xamarin.Forms.Maps 1.3.1.6296

    Do need other info? I'm trying to use geolocator and I use Xamarin Studio.

    I get a not found error (XFormsApplicationDelegate could not be found) in AppDelegate declaration so I use:

    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
    this.SetIoc ();

            global::Xamarin.Forms.Forms.Init ();
            global::Xamarin.FormsMaps.Init ();
    
            LoadApplication (new App ());
    
            return base.FinishedLaunching (app, options);
        }
    
        /// <summary>
        /// Sets the IoC.
        /// </summary>
        private void SetIoc ()
        {
            var resolverContainer = new SimpleContainer ();
    
            //resolverContainer.Register<IDevice> (t => AppleDevice.CurrentDevice) 
            resolverContainer.Register<IDisplay> (t => t.Resolve<IDevice> ().Display)
                .Register<IDependencyContainer> (t => resolverContainer);
    
            Resolver.SetResolver (resolverContainer.GetResolver ());
        }
    

    AppleDevice is not found so I comment that line.

    Thanks.

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    Xamarin.Forms.Labs 1.2.0 does NOT support Xamarin.Forms 1.3.x use this Nuget http://www.nuget.org/packages/XLabs.Forms/2.0.0-pre91

  • PaulHazlettPaulHazlett USMember ✭✭

    Like a few others in this thread, I'm sort of stuck with getting AppleDevice to resolve. I used the package console extension in Xamarin Studio to execute the following NuGet commands:

    Install-Package XLabs.Core -Pre
    Install-Package XLabs.Serialization -Pre
    Install-Package XLabs.IoC -Pre
    Install-Package XLabs.Platform -Pre
    Install-Package XLabs.Forms -Pre

    The package console reported all 5 of these packages where version 2.0.0-pre91 and now everything resolves except AppleDevice. What have I overlooked?

  • PaulHazlettPaulHazlett USMember ✭✭

    We'll it turns out that I just right-clicked on all XLabs packages and removed them. Then I reinstalled them all in this order and AppleDevice can now be resolved (not that the order should matter). Also note that Core was not explicitly installed, it was automatically pulled in as a dependency:

    Install-Package XLabs.Platform -Pre
    Install-Package XLabs.Ioc -Pre
    Install-Package XLabs.Serialization -Pre
    Install-Package XLabs.Forms -Pre

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    As I don't use the console for managing nuget I can't say what is going wrong there :) Normally, if you're installing XLabs.Forms all others are getting installed as dependencys. At least that is how it worked here.

  • LuisMarquesLuisMarques GBMember, University ✭✭

    Hi guys thanks for the helpful comments. I will try later tonight removing and re-installing all nugets (for the 3rd time). I have as stated on my post XLabs nugets and in theory it should work but visual studio kept complaining. I'll report back later. Maybe xamarin could consider putting some course work on xamarin university about XLabs - it's a great community project it seems...

  • Thanks to @RaphaelSchindler I solved.
    Maybe XLabs could have more howto guides (for stable and developing version)...

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    @FabioMarcone You're welcome

  • LuisMarquesLuisMarques GBMember, University ✭✭

    Hi @FabioMarcone how did you solve it exactly? Was it by removing all packages relates to XLabs and re-installing them in the order that @PaulHazlett recommended? I didn't realise the order mattered!
    I'm asking because I want to be 100% clear on the order etc. can you also tell me how your app delegate class definition looks like? What class does it inherit from and what specific usings have you included. Thanks in advance.

  • rmarinhormarinho PTMember, Insider, Beta Xamurai

    Hey guys, you should try XLabs 2.0 pre, make sure you try to check all dependencies are in the same version XLabs - Core 2.0.0-pre91 .

  • LuisMarquesLuisMarques GBMember, University ✭✭

    Hi All, so I removed all my XLabs nugets, re-installed them again (note that I looked for the pre91 pre release version but it didn't appear on the search list anymore. I believe it was released finally yesterday because the stable version has 2.0 with 04/02 date). So anyway, I re-installed every nuget and followed the same order as Paul described:

    All version 2.0
    XLabs.Platform
    XLabs.Ioc
    XLabs.Serialization
    XLabs.Forms

    The only difference is that I used the normal way of installing in visual studio (didn't do console commands).

    Following the wiki on https://github.com/XLabs/Xamarin-Forms-Labs/wiki
    it says:
    On iOS you can just change in your AppDelegate.cs to this:
    public partial class AppDelegate : XFormsApplicationDelegate

    When I do this, Visual studio says that he can't find XFormsApplicationDelegate.

    So finding the same error as before Can't figure out what is wrong...

    If instead I define it as:
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate

    (which goes against what the wiki says)

    and then in the same AppDelegate class I define the method:
    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());
    }

    Visual studio again complains about resolverContainer.Register<XLabs.Platform.Device.IDevice>(t => AppleDevice.CurrentDevice)

    stating that t => AppleDevice.CurrentDevice"Cannot convert lambda expression to type 'System Type' because it is not a delegate type"

    These are all XLabs usings:
    using XLabs.Forms;
    using XLabs.Serialization;
    using XLabs.Platform;
    using XLabs.Ioc;
    using XLabs.Platform.Device;
    using XLabs.Platform.Services;
    using XLabs;

    Guys, @FabioMarcone, @PaulHazlett, @rmarinho, @SKall, @RaphaelSchindler can one of you maybe paste your AppleDelegate definition, your usings, and package references? Just make sure the sample code you are posting is using the latest Xamarin Forms version and the latest XLabs version (otherwise it may work for you because you are using older libraries). This is so I can determine what I'm missing. I tried everything I can think of and followed every advice on wiki & this thread but can't make it work :disappointed:

  • I use Xamarin Studio, I had install Package Management Console add in and then I had deinstall old Lab version 1.2.0 from ide and then install XLabs 2.0.0-pre91 using console. The 2.x version solve your problems (you hav to use public partial class AppDelegate : XFormsApplicationDelegate like showed by samples).

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    This is my AppDelegate and I hope this helps you.

    using Foundation;
    using mCRM.Views;
    using Toasts.Forms.Plugin.iOS;
    using UIKit;
    using Xamarin.Forms;
    using XLabs.Forms;
    using XLabs.Platform.Device;
    using XLabs.Platform.Services.Media;
    using XLabs.Ioc;
    using XLabs.Platform.Services;
    
    namespace mCRM.iOS
    {
        [Register("AppDelegate")]
        public partial class AppDelegate : XFormsApplicationDelegate
        {
    
            public override bool FinishedLaunching(UIApplication app, NSDictionary options)
            {
                Forms.Init();
                ToastNotificatorImplementation.Init();
                SetIoC();
    
                LoadApplication(new App());
    
                return base.FinishedLaunching(app, options);
            }
    
            private void SetIoC()
            {
                var resolverContainer = new SimpleContainer();
    
                resolverContainer.Register<IDevice>(t => AppleDevice.CurrentDevice)
                    .Register<IPhoneService>(t => t.Resolve<IDevice>().PhoneService)
                    .Register<IAudioStream>(t => t.Resolve<IDevice>().Microphone)
                    .Register<INetwork>(t => t.Resolve<IDevice>().Network)
                    .Register<IDependencyContainer>(resolverContainer);
    
                Resolver.SetResolver(resolverContainer.GetResolver());
            }
        }
    }
    
  • SKallSKall USMember ✭✭✭✭

    This is our iOS sample applications app delegate:

    https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/Samples/XLabs.Sample.iOS/AppDelegate.cs

    I have tested the latest 2.0 release package multiple times by just installing XLabs.Forms package. It has pulled in all dependencies automatically every single time.

    If you are having issues with resolving namespaces and where things are located then I suggest installing the trial version of Resharper. Chances are you will find it will save you a LOT of time and is well worth the price. Personal license (which you can use anywhere including business) is only $149.

  • powerdudepowerdude USMember ✭✭

    @LuisMarques, what is your namespace? This seems like a namespace problem because you have Xamarin.Forms in your namespace.

  • LuisMarquesLuisMarques GBMember, University ✭✭

    Thank you all for your assistance. Unfortunately I haven't been able to fix this issue. I will probably have to spend another day's worth banging my head against the wall until I find what is wrong!! During the weekend I will have a look at the sample @SKall provided to compare the differences in the 2 projects' nugets. One thing is certain, I am now 99.999% certain its nothing in the code. It must be the project configuration, some conflict on the nuget packages, or something like that. I have removed all Xlabs and reinstalled them all again, did what SKall suggested and installed only XLAbs.Forms which in turn downloaded all other dependencies but Visual Studio still says it doesnt recognise the name XFormsApplicationDelegate....

    Here is my full App Delegate:

    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.Platform.Device;
    using XLabs.Platform.Services.Media;
    using XLabs.Ioc;
    using XLabs.Platform.Services;
    
    namespace NoteTakerPCL.iOS
    {
        // The UIApplicationDelegate for the application. This class is responsible for launching the 
        // User Interface of the application, as well as listening (and optionally responding) to 
        // application events from iOS.
        [Register("AppDelegate")]
    //    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
        public partial class AppDelegate : XFormsApplicationDelegate
        {
            // class-level declarations
            //
            // This method is invoked when the application has loaded and is ready to run. In this 
            // method you should instantiate the window, load the UI into it and then make the window
            // visible.
            //
            // You have 17 seconds to return from this method, or iOS will terminate your application.
            //
            public override bool FinishedLaunching(UIApplication app, NSDictionary options)
            {
                global::Xamarin.Forms.Forms.Init();
                Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
                LoadApplication(new App());
    
                return base.FinishedLaunching(app, options);
            }
    
            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());
            }
        }
    }
    
  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭
    edited February 2015

    Try to replace your using Directives with mine.

    using Foundation;
    using UIKit;
    using Microsoft.WindowsAzure;
    using Xamarin.Forms;
    using XLabs.Forms;
    using XLabs.Platform.Device;
    using XLabs.Platform.Services.Media;
    using XLabs.Ioc;
    using XLabs.Platform.Services;
    
  • LuisMarquesLuisMarques GBMember, University ✭✭

    @RaphaelSchindler i will do as you suggest tomorrow morning and report back. Can you do me a quick favour - where exactly is this class defined? Which nuget? Which using directive enables the name to be recognised when referred to? Is it XLabs.Forms; or XLabs.Platform? Just wondering where this magical class is defined ;-)

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    @LuisMarques The XFormsApplicationDelegate is part of the XLabs.Forms Nuget is XLabs 2.0.0 -pre91

  • LuisMarquesLuisMarques GBMember, University ✭✭

    @RaphaelSchindler Ok - thanks, good to know where exactly the class is defined - quite weird though that I have the XLabs.Forms using directive but somehow it's still invisible. You said XLabs 2.0.0 -pre91 - to be clear - I didn't find any pre-release versions of XLabs the last 2 days I checked. They were appearing in the visual studio search list about 3 days ago, but not now. I think that there is only a single stable release available at the moment and that is the one visual studio downloads from nuget. Wondering if you use some console command to install them or if you just download them normally via visual studio drop down menu - add packages

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    @LuisMarques It seems that 2.0.0 has hit the stable release so you will only find that right now but it is the same as 2.0.0 pre91 with some bug fixes as I can see. The package has last release on 4th February 2015. Could you try the newest Xamarin.Forms pre Version that is at the moment 1.3.3.6231 pre2

  • LuisMarquesLuisMarques GBMember, University ✭✭

    @RaphaelSchindler Ok thanks for confirming - I wonder if this latest stable XLabs also works with your app delegate.

    Anyway, I'll try tomorrow morning with the using directives you suggested and remove all the other ones. In fact I'll add them one by one and re-build each time to see if the class at some point becomes visible...

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    @LuisMarques Just changed from 2.0.0 pre91 to stable 2.0.0 and it works.

  • LuisMarquesLuisMarques GBMember, University ✭✭

    Ok good to know it's not anything wrong with the new stable package. What a mystery !! :-) I'll report back tomorrow morning.

  • LuisMarquesLuisMarques GBMember, University ✭✭

    Hi Guys, I finally found what was wrong! The way I found it was by starting a new Xamarin.Forms project and then adding XLabs.Forms to that brand new forms project. I noticed that it immediately recognized that mysterious XFormsApplicationDelegate class. I then suspected that it could be because of the fact that the brand new template for Xamarin.Forms was already migrated to Xamarin.iOS Unified - I compared the references of that new project with mine and saw differences - mine said iOS.classic, and the new one had no such reference. From there I just had to find the migration "how to" page and post migration, the class became "visible" to Visual Studio and the issues vanished. So now you all know, XLabs is only compatible with Xamarin.iOS unified, not classic... My fault, I should have upgraded weeks ago but never crossed my mind this was the reason for all the head ache!

    Thank you all for your feedback - and special thanks to @RaphaelSchindler for your huge patience and constant helpful examples and answers. Knowing the class was in XLabs.Forms and that the new package worked fine with your project was key to direct troubleshooting to other areas.

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    @LuisMarques Great that it works now. I should have asked earlier if you upgraded to unified :neutral:

  • akshayaakshaya USMember, University

    I installed XLabs - Forms 2.0.5522 (latest stable) 161 Saturday, February 14 2015
    However when I am trying to takepicture (camera feature) in Android it fails with a runtime error as below
    The class Android.OS.BaseBundle could not be loaded, used in XLabs.Platform.Droid

    How to resolve this.

    My code is as below
    public class MainActivity : XFormsApplicationDroid
    {
    private static bool _initialized;
    protected override void OnCreate(Bundle bundle)
    {
    base.OnCreate(bundle);
    if (!_initialized)
    {
    this.SetIoc();
    }

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
    
        }
    
        /// <summary>
        /// Sets the IoC.
        /// </summary>
        private void SetIoc()
        {
            var resolverContainer = new 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<IXFormsApp>(app);
    
    
            Resolver.SetResolver(resolverContainer.GetResolver());
    
            _initialized = true;
        }
    

    }

  • akshayaakshaya USMember, University

    I installed XLabs - Forms 2.0.5522 (latest stable) 161 Saturday, February 14 2015
    However when I am trying to takepicture (camera feature) in Android it fails with a runtime error as below
    The class Android.OS.BaseBundle could not be loaded, used in XLabs.Platform.Droid

    How to resolve this.

    My code is as below
    public class MainActivity : XFormsApplicationDroid
    {
    private static bool _initialized;
    protected override void OnCreate(Bundle bundle)
    {
    base.OnCreate(bundle);
    if (!_initialized)
    {
    this.SetIoc();
    }

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
    
        }
    
        /// <summary>
        /// Sets the IoC.
        /// </summary>
        private void SetIoc()
        {
            var resolverContainer = new 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<IXFormsApp>(app);
    
    
            Resolver.SetResolver(resolverContainer.GetResolver());
    
            _initialized = true;
        }
    

    }

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @LuisMarques and @RaphaelSchindler:

    First, thanks for your postings here....
    I have installed XLabs a longer time ago, but only have used the PopUp-Control (Xlabs.forms).
    Now, I want to use some services from XLabs (including device) and have exactly the same problems as Luis:

    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"

    I have searched for hours and finally also had a look to my references (thanks your posting, Luis).
    In difference to Luis, I have done the migration to unified (according to the description) and thought, that I am on unified (also as I have not other problems)...
    Now, I have seen, that it seems, as the migration with the tool was not or only partially done :disappointed:
    My references targets still montotouch10 (ios.classic), in my csproj-file still the old key is in included, and I have still usings with monotouch-namespace (but I have found only 2 in the AppDelegate.cs-file).

    I also have tried, to run the migration-tool once again - nothing happens :bawling:

    Questions:
    - Does somebody knows, what the migration-tool exactly does?

    According to the Xamarin-documentation (to manually migrate an iOS-project), the following steps are to do:

    • change a key and project-setting in the csproj-file
    • remove the references to the monotouch.10 and replace it with references to Xamarin.iOS10
    • remove the monotouch-namespace
      - done...?

    In don't like that, as I fear to "destroy" my project (I also don't understand, that I have no other problems, as I also have done already the manual changes in all projects).

    Any suggestions...?

    Thanks for every reply!

    P.S.
    I also create a description, how to install and use XLabs and will post it then here in the forum.

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    @FredyWenger Hi and sorry for the late response, I was on vacation. Do you get compile Errors if you're compiling your app and AppleDevice is red underlined? I had the same behaviour and sometimes it is underlined and sometimes not. I don't know the exact reason why but as long as no problems occur I don't really care^^

    I just looked in my .csproj of the iOS project and I too have a reference to monotouch10 after using the migration tool. Seems to be ok.

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @RaphaelSchindler:
    Thanks for your "late? response" .
    I hope you had a nice holiday... :sunglasses::sunglasses::sunglasses:

    If you really have your references (e.g. to Xamarin.Forms.Core) already to monotouch, I suggest you to update to unified (as I think, you will have problems else....).
    As I have loosed now full two day's with the problems (first the unified-problem, then a further problem wit Xamarin.Mobile), I have posted my findings in a new thread (in the hope, that may help some other developers like us - maybe also you :innocent:)

    Link:
    forums.xamarin.com/discussion/35928/information-problems-update-xf-to-unified-appledevice-xamarin-mobile-xlabs?new=1

    Once again, thanks for your help...

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @All readers of this thread:

    I have implemented XLabs and thereby created a documentation (.pdf).
    You will find it here:
    forums.xamarin.com/discussion/35991/how-to-install-setup-and-use-xlabs?new=1

Sign In or Register to comment.