Hi Chris,

Thanks a lot and, some hours later and trying to find something (I didn't
understood very well iOS delegates vs Mono yet, lol), I found on Main.cs
that I can override here the void HandleOpenURL (UIApplication application,
NSUrl url)Š Well.. Duh, it's inside public partial class AppDelegate :
UIApplicationDelegate that, duh, it's our UIApplicationDelegate.

Well, with this test, it is executed each time I type myapp:// on safari:

public override void HandleOpenURL (UIApplication application, NSUrl url)
{
Console.WriteLine(url.AbsoluteString);
}

Well if this is a simple application with one viewcontroller inside main, I
think it's ok, but do not solved yet my problem, that is detect this inside
a predetermined ViewController. The application has many view controllers as
a windows mobile has many forms. SoŠ I tried some weird thinking that I
don't know if I'm completely wrong or what, but apparently solved the
problem. I have a Program class that came from Windows Mobile application
original version, that has essentially some static variables like user, name
of user, other few info to quick access from anywhere, then I made:

// The name AppDelegate is referenced in the MainWindow.xib file.
public partial class AppDelegate : UIApplicationDelegate
{
// This method is invoked when the application has loaded its UI and its
ready to run
public override bool FinishedLaunching (UIApplication app, NSDictionary
options)
{
window.AddSubview (navigationControllerMain.View);
window.MakeKeyAndVisible();
Program.appDelegate = this; // Inside Program class I put a public
AppDelegate appDelegate { get; set; }Š..
return true;
}
// Handle a new event ApplicationCalled from outside
        public event System.EventHandler ApplicationCalled;
        public virtual void OnApplicationCalled(EventArgs e)
        {
            System.EventHandler handler = ApplicationCalled;
            if (handler != null)
            {
                // Invokes the delegates
                handler(this, e);
            }
        }
public override void HandleOpenURL (UIApplication application, NSUrl url)
{
Program.url = url; // Added a public static NSUrl url { get; set; } on
Program class
EventArgs e = new EventArgs();
this.OnApplicationCalled(e);
}
// End handler for new public eventŠ
}

So, inside some view controller (I like to call viewcontrollers as
FormExternalApp.cs, like on windows, for code symmetry) I put:

public override void ViewDidLoad()
{
base.ViewDidLoad();
Program.appDelegate.ApplicationCalled += HandleAppDelegateApplicationCalled;
// add the event handler to event
}

void HandleAppDelegateApplicationCalled (object sender, EventArgs e)
{
Console.WriteLine("Called from outside. Url: {0}",
Program.url.AbsoluteString);
}

So, if user is on the FormExternalApp and call the external App, when the
external App calls back myApp, then the HandleAppDelegateApplicationCalled
is called. Just must be careful with the execution time of
HandleAppDelegateApplicationCalled that enters the 10 seconds ruleŠ so I
think that must create another event, local to the FormExternalApp view
controller, or something like that in cases when
HandleAppDelegateApplicationCalled must take more than 10 secondsŠ or to
find something like DidViewAppear that could be called when application is
called backŠ..

Sorry for may noobismŠ

Karl

From:  ChrisNTR <[email protected]>
Date:  Thu, 14 Jul 2011 20:45:06 +0100
To:  Karl Heinz Brehme Arredondo <[email protected]>
Cc:  Wally McClure <[email protected]>,
"[email protected]" <[email protected]>
Subject:  Re: [MonoTouch] Call my App from third one

Hey Karl,

You might want to override the "HandleOpenUrl" method on
UIApplicationDelegate to handle this as per the docs -
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAppl
icationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIAp
plicationDelegate/application:handleOpenURL:

Let me know if this works for you,

Cheers,

ChrisNTR

-- 
ChrisNTR
Microsoft ASPInsider
http://weblogs.asp.net/chrishardy
http://twitter.com/chrisntr


_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to