Question regarding URL handling in xCode

Discussion in 'Mac Programming' started by bscenefilms, Nov 2, 2010.

  1. macrumors newbie

    Joined:
    Nov 2, 2010
    #1
    Howdy folks. I have an OSX app that was written by a 3rd party for the company I work for and it has worked fine for a number of years. The app allows a user to view video content on a DVD and it lists out chapters and links to movies etc. It is driven by an XML file that describes the particular content for a given DVD title.

    One of the things that this app does is it allows the user to fill out a survey online to provide feedback. They click a button in the UI of the app and it launches the default browser and takes them to the web survey.

    Recently, we changed the way that the feedback survey is done and the URL for it has changed. In the past, the URL would look like this:

    http://www.somesurveyprovider.com?ldp=5432dasa4321tt543121

    And that worked fine with the application. This survey data was read by the app from the XML file setup like this:

    <survey>http://www.somesurveyprovider.com?ldp=5432dasa4321tt543121</survey>

    Now, with the change to the survey, the URL is more like this:

    https://www.somesurveyprovider.com/se.ashx?s=7A596FE76ACA99E1&CourseID=48369&AuthorName=Some Dude&CourseName=Some Course Name

    So I changed the XML generator to encode this like this:

    <survey><![CDATA[https://www.somesurveyprovider.com/se.ashx?s=7A596FE76ACA99E1&CourseID=48369&AuthorName=Some Dude&CourseName=Some Course Name]]></survey>

    Now, however, the user clicks the button and nothing happens. No error message - nothing.

    Now, I should prefix this by saying that I am NOT and xCode developer. I am a .NET dev using C#. Regardless of that, my boss asked me to look at this and see if I can figure out why this fails (we also have a Windows version of the same app that uses the same XML file and it still works fine).

    So, after getting xCode on a Mac here, loading up the application source into that, then going back and re-installing xCode to add the 10.4 support and then setting the GCC compiler to version 4.0, I am able to compile, run and test the app. So far, so good :)

    Looking in the code, it would appear that this line is what executes the survey button push:

    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:
    [trainingMgr surveyAddress]]];

    At first I suspected that the XML parsing might have had an issue with the CDATA section so I added this:

    NSLog([trainingMgr surveyAddress]);

    And the output it produced was this:

    Running…
    (gdb) continue
    Current language: auto; currently objective-c
    2010-11-02 09:27:34.334 lynda.com player[3261:a0f] https://www.somesurveyprovider.com/se.ashx?s=7A596FE76ACA99E1&CourseID=48369&AuthorName=Some Dude&CourseName=Some Course Name
    (gdb) continue

    So based on that, I am assuming that it parsed the URL correctly.

    Can anyone shed any light here on why this might fail with this URL but not with the previous one?

    TIA!
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    XCode is an Integrated Development Environment. It does not care about URLs. I believe you mean Cocoa. Which is the Framework used to write Mac applications.

    With that out of the way I would suggest your problem might be that you have spaces in your URL. Which are illegal. They must be encoded. NSString provides the handy stringByAddingPercentEscapesUsingEncoding: for this very purpose.
     
  3. thread starter macrumors newbie

    Joined:
    Nov 2, 2010
    #3
    Thanks so much, Robbie.

    What would the syntax be to add that method to:

    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:
    [trainingMgr surveyAddress]]];
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Erm, do you know how to write Objective-C code? Because I basically have no interest in spoon feeding you answers one at a time until you learn.

    This is the one and only piece of code I'm posting: if this doesn't work you are on your own working this out

    Code:
    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:
    [[trainingMgr surveyAddress] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]];
    
     
  5. thread starter macrumors newbie

    Joined:
    Nov 2, 2010
    #5
    Hi Robbie. Thanks a TON for doing this. That was exactly the issue and it works fine now. This was basically a one-off deal. The company that wrote this app is out of business and since I am one of the few programmers here (C# tho...) I was tagged to see if I could figure out the issue.

    Your solution was spot on. Thank you VERY much for taking the time to do this and I promise not to bug you again :)
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Now I'm worried for you. You have just become the Cocoa/Objective-C guy in managements eyes :p
     
  7. thread starter macrumors newbie

    Joined:
    Nov 2, 2010
    #7
    Oh trust me, I took NO credit for figuring it out :)

    I was lucky to find the line of code that needed adjustment :)
     

Share This Page