将两个登录系统集成到一个应用程序中 [英] Integrating two login system into an app
问题描述
我正在尝试将Facebook和Foursquare登录系统集成到我的应用程序中。但是,我不知道如何编辑 myapp.plist
下的URL类型和URL方案。我应该只在URL方案下添加新项目还是创建新的URL类型?
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?
这是Facebook登录的图片。
This is the image for Facebook login.
推荐答案
看起来您只是想创建一个自定义URL方案。为此,请执行以下操作:
It looks like you're just trying to create a custom URL scheme. To do this, do something like this:
然后,在设备上发送到 myapp:// whatever-url
的所有URL请求都将是导入您的应用程序。您可以使用以下方法在应用程序的app delegate文件中识别它们。我假设您正在通过URL(如令牌)将数据发回给您,并且您需要检索该信息,因此您需要解析该URL。
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
可以字面意思无论你想要什么。这里的目的是发送一个只会将用户引导到您的应用的网址。因此, 必须 是独一无二的。例如,不要使用 fb
,因为这是Facebook应用程序使用的。
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.
这篇关于将两个登录系统集成到一个应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!