strange error ! url returning nil !

Discussion in 'iOS Programming' started by chhoda, Dec 12, 2008.

  1. macrumors 6502

    Joined:
    Oct 25, 2008
    #1
    Hi All,

    I am getting a strange error.

    NSString *filePath = [[NSBundle mainBundle] pathForResource:mad:"direction" ofType:mad:"html"];

    // NSString *params = [NSString stringWithFormat:mad:"?dirstr=%@", @"from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)"/*directioncommand*/];
    // filePath = [filePath stringByAppendingString:params];

    NSString *fileURLString = [[NSURL fileURLWithPath:filePath] absoluteString];
    NSString *params = [NSString stringWithFormat:mad:"?dirstr=%@", @"from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)"/*directioncommand*/];
    fileURLString = [fileURLString stringByAppendingString:params];
    NSURL *fileURL = [NSURL URLWithString:fileURLString];


    I am trying to for an url and append parameter to it. unfortunately I am getting url as nil. Is there any way i can see the error ? If i copy paste the string from nslog to the browser it works fine.

    thanks and regards
    ch
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    I would guess it's because the parameter part of your URL contains spaces (i.e. "from: 500 Memorial Drive..."), which isn't allowed. Try calling stringByAddingPercentEscapesUsingEncoding: on it first.
     

Share This Page