Running Safari from application
Running Safari from application
- Subject: Running Safari from application
- From: Bartosz Białecki <email@hidden>
- Date: Fri, 18 Sep 2009 10:26:41 +0200
- Organization: Nowa Poczta Wirtualnej Polski S.A. http://www.wp.pl/
Hi,
I try to open local html file in Safari from my application. I use this
code:
- (void)viewDidLoad
{
[super viewDidLoad];
username = [[NSUserDefaults standardUserDefaults] stringForKey:
@"username"];
password = [[NSUserDefaults standardUserDefaults] stringForKey:
@"password"];
if ([username length] == 0 || [password length] == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: alertTitle
message: alertMessage delegate: self cancelButtonTitle:
alertCancelButtonTitle otherButtonTitles: nil];
[alert show];
[alert release];
} else {
if ([self saveHtmlFile])
[self showPageInSafari];
}
}
- (void)alertView:(UIAlertView *)alertView
didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
exit(0);
}
}
- (BOOL) saveHtmlFile
{
NSString *fileContent = [NSString stringWithFormat:
@"<html><head><script type=\"text/javascript\">function send_request() {
var form = document.getElementById(\"login\"); form.submit();
}</script></head><body onload='send_request();'><form id='login'
action='https://www.example.com/index.php' method='post'><input
id='username' name='username' type='hidden' value='%@' /><input
type='hidden' id='password' name='password' value='%@'
/></form></body></html>",
username, password];
NSError *error;
return [fileContent writeToFile: [self getPathToHtmlFile] atomically:
YES encoding: NSUnicodeStringEncoding error: &error];
}
- (void) showPageInSafari
{
[[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath:
[self getPathToHtmlFile]]];
}
- (NSString *) getPathToHtmlFile
{
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSDocumentDirectory, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [NSString stringWithFormat: @"%@/login.html", documentsDirectory];
}
The problem is that the safari is not launched. If I put in
showPageInSafari function openURL: [NSURL URLWithString:
@"http://www.example.com/index.php"] then it works. Do you know what is
wrong?
Thanks
Bartosz Bialecki
----------------------------------------------------
Znajdź mieszkanie dla siebie!
Porównaj i kup.
http://klik.wp.pl/?adr=http://corto.www.wp.pl/as/ogloszenia_nier.html&sid=862
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden