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%3A%2F%2Fcorto.www.wp.pl%2Fas%2Fogloszenia_nier.html&sid=862


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to