Alert, OpenURL etc

Monkey Targets Forums/iOS/Alert, OpenURL etc

xzess(Posted 2011) [#1]
Please give this a try, this should theoretically work:
I will test it myself when i finished my breakfast and coffee :)
Just wrote it on my Iphone in the notes ^^

Here is a Tutorial how you can add it to a own module (Thanks to Lumooja):
http://www.monkeytools.net/articles/Adding_new_commands_to_Monkey

This opens the E-Mail Composer with a prepared Message
Void UIEmail( String MailAdress,String Subject, String Body )
{
NSString *NSstrMailAdress = MailAdress.ToNSString();
NSString *NSstrBody = Body.ToNSString();
NSstrBody = [NSstrBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *NSstrSubject = Subject.ToNSString();
NSstrSubject = [NSstrSubject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSString *message = [NSString stringWithFormat:@"mailto:%@?subject=%@&body=%@",NSstrMailAdress,NSstrSubject,NSstrBody];

//Open E-Mail And add message
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:message]];
}


Same for Browser, This opens a Webpage in Safari
Void UIBrowser( String URL )
{
NSString *NSstrURL = URL.ToNSString();
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:NSstrURL]];
}

AlertBox, the Messagebox for iOS
Void UIAlert( String title, String message, String buttoncaption )
{
NSString *NSstrTitle = title.ToNSString();
NSString *NSStrMessage = message.ToNSString();
NSString * NSStrButtonCaption = buttoncaption.ToNSString();

UIAlertView *openURLAlert = [[UIAlertView alloc] initWithTitle:NSstrTitle message:NSStrMessage delegate:nil cancelButtonTitle:NSStrButtonCaption otherButtonTitles:nil];
[openURLAlert show];
[openURLAlert release];
}


Simple vibrate Function
Void Vibrate()
{
//Needed refs: Audio Toolbox, Core Audio, OpenAL
//In Xcode goto Frameworks And Select Add > Existing Framework
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
}


I will add more soon...
You can use it as you like


xzess(Posted 2011) [#2]
Query HTML from a Webpage and return as String
String HtmlQuery( String URL )
{
NSString *NSstrURL = URL.ToNSString();
NSURL *url = [NSURL URLWithString:NSstrURL];
NSString *content = [NSString stringWithContentsOfURL:url];
return String( content );
}


Debug Log
void DebugLog( String DebugMessage)
{
NSString *logstr = DebugMessage.ToNSString();
NSLog(logstr);
}



Xaron(Posted 2011) [#3]
Thanks looks good! That HTMLQuery should work with my MNet as well. ;)


xzess(Posted 2011) [#4]
Guten morgen :D and a good morning to everybody else :)


xzess(Posted 2011) [#5]
Save some Data to your Application Preferences (like a highscore or something else) (App Preferences is the iOS App registry)

@Xaron ;)

Void SaveAppPreferences( String Key, String Value )
{
NSString *NSstrKey = Key.ToNSString();
NSString *NSstrValue = Value.ToNSString();
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:NSstrValue forKey:NSstrKey];
}


Returns the Value of the Key which is stored in Application Preferences
String LoadAppPreferences( String Key )
{
NSString *NSstrKey = Key.ToNSString();
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *recValue = [prefs stringForKey:NSstrKey];
Return String( recValue );
}



xzess(Posted 2011) [#6]
anybody gave this a try?

can anybody tell me whats the best way to integrate this into a module?


Hima(Posted 2011) [#7]
Maybe you can do it like in Diddy. It comes with a monkey file that wrap all the native codes and a native folder where all the native files reside. This way we could use your module easily by just copy it to Monkey's module folder :)

Anyway, I'll test these and come back with feedback later!


marksibly(Posted 2011) [#8]
Hi,

You'll need to stick all the above code in a 'native' cpp file and add a monkey wrapper, eg:

'file modules/xzess/xzess.monkey

Import "native/xzess.cpp"  'contains native cpp code

Extern

Function UIEMail( address$,subject$,body$ )
Function UIBrowser( URL$ )
Function UIAlert( title$,message$,caption$ )
Function Vibrate()
Function HTMLQuery( URL$ )
Function DebugLog( message$ )
Function SaveAppPreferences( key$,value$ )
Function LoadAppPreferences$( key$ )



Then you just Import xzess - on Mac only though!