Integrating two login system into an app

醉酒当歌 提交于 2019-12-02 10:20:37

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!