Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Launching another app

$
0
0

Hi

Today I got asked a rather odd question if I can do a proof of concept app, I was asked if I can make two demo apps that will call each other I did this in objective-c easily (that's what I normally write iOS app's in) however I was asked to look into Mono and the formally known monotouch (Sorry I forget it's current name) (On a side note I didn't get told why I needed to look at mono and monotouch). Reading through the documentation I saw that I can use something like:

String myMsg = "I'm sending a msg from C# & MonoTouch";
var urlToSend = new NSUrl("readmsgtext://" + myMsg);

if (UIApplication.SharedApplication.CanOpenUrl(urlToSend)) {
    UIApplication.SharedApplication.OpenUrl(urlToSend);
} else {
    // warn the user, or hide the button...
    Console.WriteLine ("Cannot open url: {0}", urlToSend.AbsoluteUrl);
    String errorMsg = urlToSend.ToString();

    var alertView = new UIAlertView("Error", errorMsg, null, "OK", null);

    alertView.Show();
}

However when trying this for a custom app I simply cannot get it to launch! and the 'errorMsg' returns nothing but MonoTouch.Foundation.NSUrl. Here is what I use in objective-c to launch a "second" app and send a message.

// Sending app

NSString *msgToSend = @"Hello World";

// Opens the Receiver app if installed, otherwise displays an error
UIApplication *ourApplication = [UIApplication sharedApplication];

NSString *ourPath = [@"readmsgtext://" stringByAppendingString:msgToSend];
NSString *URLEncodedText = [ourPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *ourURL = [NSURL URLWithString:URLEncodedText];

if ([ourApplication canOpenURL:ourURL]) {
    [ourApplication openURL:ourURL];
} else {
    //Display error
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Not Found"
                                                        message:@"The App is not installed. It must be installed to send text."
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
    [alertView show];
}

Changes are I'm missing something simple but I really could do with some help on this one

many thanks for your patience and time.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>