0

I'm trying to integrate both a Facebook and a Foursquare login system into my app. However, I have no idea how to edit the URL type and URL scheme under the myapp.plist. Should I just add a new item under URL scheme or create a new URL type?

Screenshot

This is the image for Facebook login.

rebello95
  • 8,486
  • 5
  • 44
  • 65
user3526002
  • 537
  • 2
  • 8
  • 19

1 Answers1

2

It looks like you're just trying to create a custom URL scheme. To do this, do something like this:

Example

Then, all URL requests that are sent to myapp://whatever-url on the device will be directed into your app. You can identify them in the app delegate file of your app using the following method. I'm assuming you're getting data sent back to you in the URL (like a token) and you need to retrieve that information, so you'll need to parse the URL.

//Handles URL schemes specified in the info.plist file
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    //Get the URL in string format
    NSString *urlString = [url absoluteString];

    //See if the URL contains part of the URL we're expecting (ie this is the base URL with data like a token appended to it)
    if ([urlString rangeOfString:@"myapp://url_one"].location != NSNotFound) {

        //Parse the URL
        //Reference: http://stackoverflow.com/questions/8756683/best-way-to-parse-url-string-to-get-values-for-keys
        NSMutableDictionary *queryStringDictionary = [[NSMutableDictionary alloc] init];
        NSArray *urlComponents = [urlString componentsSeparatedByString:@"&"];

        for (NSString *keyValuePair in urlComponents) {

            NSArray *pairComponents = [keyValuePair componentsSeparatedByString:@"="];
            NSString *key = [pairComponents objectAtIndex:0];
            NSString *value = [pairComponents objectAtIndex:1]; //Make sure this is URL decoded

            //Add the value to an array, dictionary, etc. for usage later here
        }
    }

    return TRUE;
}

myapp can literally be whatever you want. The purpose here is to send a URL that will only direct users to your app. So, this must be something unique. For example, don't use fb because that's used by the Facebook app.

rebello95
  • 8,486
  • 5
  • 44
  • 65
  • can u add some more details – Anbu.Karthik Aug 23 '14 at 09:52
  • Like what, it's really that simple... You can see what URL was sent using `[url absoluteString]`. – rebello95 Aug 23 '14 at 09:54
  • Can you please tell me which url need to place for 'whatever-url' in myapp://whatever-url and add some code in this method. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url – Mahesh_P Aug 23 '14 at 10:06