Forum Xamarin.iOS

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

OpenUrl not being called

clintclint CAMember

Hi,

I am trying to receive a custom file format from the mail application and I have it all working except for the part where the application actually receives the file when the application is already launched.

From what I have read I was expecting that my OpenUrl method would be called when launched from another process but it doesn't appear to ever be called. If the app isn't running I am able to get a FinishedLaunching with options set.

Anyone have any ideas?

Testing on an iPhone 4S with iOS 7.0.4 using Xamarin Studio 4.3.1 (build 3).

Cheers,
Clint

Posts

  • clintclint CAMember

    So I went ahead and added all of the overrides to my UIApplicationDelegate class expecting to at least see some of the methods called as iOS did its lifecycle but the only one I ever see is the FinishedLaunching(app, options) when the application is starting for the first time.

    Is this a bug in the runtime?

    I tried a Objective-C based project as a test and it works just fine I know that it isn't something with my version of iOS or my device.

    I am really at a loss as to what could be broken here or if there is something I didn't enable to get the desired functionality.

  • clintclint CAMember
    edited January 2014

    I should have included the list of overrides that I am trying:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        System.Diagnostics.Debug.WriteLine("FinishedLaunching Called");
    
        return true;
    }
    
    public override void OnResignActivation(UIApplication application)
    {
        System.Diagnostics.Debug.WriteLine("OnResignActivation Called");
    }
    
    public override void DidEnterBackground(UIApplication application)
    {
        System.Diagnostics.Debug.WriteLine("DidEnterBackground Called");
    }
    
    public override void WillEnterForeground(UIApplication application)
    {
        System.Diagnostics.Debug.WriteLine("WillEnterForeground Called");
    }
    
    public override void ProtectedDataDidBecomeAvailable(UIApplication application)
    {
        System.Diagnostics.Debug.WriteLine("ProtectedDataDidBecomeAvailable Called");
    }
    
    public override void WillTerminate(UIApplication application)
    {
        System.Diagnostics.Debug.WriteLine("WillTerminate Called");
    }
    
    public override void OnActivated(UIApplication application)
    {
        System.Diagnostics.Debug.WriteLine("OnActivated Called");
    }
    
    public override void HandleEventsForBackgroundUrl(UIApplication application, string sessionIdentifier, NSAction completionHandler)
    {
        System.Diagnostics.Debug.WriteLine("HandleEventsForBackgroundUrl Called");
    }
    
    public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
    {
        System.Diagnostics.Debug.WriteLine("OpenURL Called");
        return true;
    }
    

    I would have expected that at least some of those would be called as I opened and closed the app.

  • clintclint CAMember

    I have now tried doing my own export but still it doesn't work...

    [Export("application:openURL:sourceApplication:annotation:")]        
    public bool MyOpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
    {
        System.Diagnostics.Debug.WriteLine("OpenURL Called");
        return true;
    }
    
  • SebastienPouliotSebastienPouliot CAXamarin Team Xamurai

    Weird, that should work (many apps do that).

    Could you have more than one type implementing UIApplicationDelegate ? the wrong one might be registered.

    Also are both your FinishedLaunching and (if used) WillFinishLaunching returning true ?

  • clintclint CAMember

    I have just the one UIApplicationDelegate. I am only using FinishedLaunching which does return true.

    My application is just a small sample app to test receiving custom file types from email.

    It just dawned on me that I was running the Xamarin.iOS from the Alpha channel since I was hoping to find some bug fixes related to the IDE. (Which weren't fixed)

    I switched back to the Stable channel and now it appears to be working. So there is some kind of bug in the version that is sitting in Alpha.

    Cheers,
    Clint

  • SebastienPouliotSebastienPouliot CAXamarin Team Xamurai

    @Clint can you file a bug report and attach your sample ? this needs to be verified (and fixed) before that alpha gets promoted.

    Also was it 7.1.x beta or 7.0.6 beta ?

    Telling us your (current) version informations would help a lot too.

    The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).

  • clintclint CAMember

    What is a bit disconcerting is that when I switched back to the Alpha channel this morning to get the details about the version and test the application it worked as it should.

    So I don't know if there was a fix overnight and this morning I got a different build or just by switching channels somehow fixed problem in some kind of voodoo magic.

    So submitting a bug will likely just end up as unreproducible.

    Cheers,
    Clint

  • MichelSzybistMichelSzybist FRMember

    Hi guys. I'm experiencing the same issue : OpenUrl is not called (although my app is displayed when opening a file from the Mail app).

    Xam Studio for iOS : 4.2.3 build 60 on latest XCode, Mavericks.

    I'll file a bug at bugzilla.xamarin.com.

    cheers,
    Michel Szybist

  • SatishBirajdarSatishBirajdar USMember ✭✭

    @MichelSzybist @clint @SebastienPouliot I still cannot open the File URL using HandleOpenURL(), did you guys found any alternative? I am trying to open an email attachment with my application.

  • RogerSchmidlinRogerSchmidlin CHUniversity ✭✭✭

    Same problem here. It used to work, but just checked again recently and it stopped working. My mail client shows my app when clicking on the attachment but nothing happens when I click it. My app or OpenUrl doesn't get called. Anyone?

  • jasonehirstjasonehirst GBMember ✭✭

    Same issue here. The app launches via the URL but OpenURL is not called.
    Help?

  • EdwardRushEdwardRush USMember ✭✭

    Did anyone ever figure out what was going on with this? I have a similar issue. I start the application fine with the OpenUrl from another application. However, the Application starting up does not appear to every hit the OpenUrl Override I have in my AppDelegate. I set a static variable value assignment in the Overrides, but they are never set by the Function. So it appears that the function never executes.

  • AlvaroRivoirAlvaroRivoir USMember ✭✭✭

    Same problem here, the method OpenUrl is never called. Any idea how to solve it?

  • SuneKjaergaardSuneKjaergaard DKMember ✭✭
    edited July 2017

    OpenUrl is never called, but it seems that ContinueUserActivity is called even when the application is started from scratch.

    So you can handle it like this:

    public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
    {
        OutputStringToConsole ("In continue useractivity");
    
        if (userActivity.ActivityType == NSUserActivityType.BrowsingWeb)
            //I found I needed to delay the handling a bit to make sure the UI was up to speed.
            System.Threading.Tasks.Task.Delay (500).ContinueWith (_ => {
                this.InvokeOnMainThread (() => {
                    OutputStringToConsole ("Calling OpenAppFromUniversalLink");
                    OpenAppFromUniversalLink (userActivity.WebPageUrl);
                });
            });
    
        return true;
    }
    
  • AllanChin.6924AllanChin.6924 USUniversity ✭✭✭

    Hi! Any luck getting OpenUrls() called? Thanks.

  • JustinTothJustinToth USMember ✭✭

    Neither OpenUrl or ContinueUserActivity are called when a deep link is launched and our Xamarin iOS app is opened. Has anyone figured out a workaround? Or will Xamarin stop ignoring this thread and fix the bug?

  • AlexSotoAlexSoto MXXamarin Team Xamurai

    Hello, I have not had any issues with this so far, I created a small sample for this, you can find it here https://github.com/xamarin/xamarin-macios/issues/6303

  • edited November 2019

    Hi Alex,
    I was able to reproduce the problem in a projects created in Visual Studio for mac 2019. The app sample you have uploaded looks different from the one Visual Studio creates for single view app.

    Please find attached the sample.

    Best Regards,
    Abhirasmanu

  • DavidJunodDavidJunod USBeta ✭✭

    If you use:

    public override bool OpenUrl(UIApplication app, NSUrl url, string sourceApplication, NSObject annotation)
    

    It will never get called. You must use:

    public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
    
Sign In or Register to comment.