我正在创建一个使用自定义 url 方案的应用程序,我已经完成了所有设置,并且在打开应用程序时它可以工作,但是,我现在希望能够向 url 添加一个字符串,以便打开的人该应用程序可以看到该字符串。我真的很挣扎,有人可以帮助我吗?
这是我的代码
- (NSDictionary*)parseURLParams:(NSString *)query
{
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs)
{
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val = [[kv objectAtIndex:1]
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[params setObject:val forKey:[kv objectAtIndex:0]];
}
return params;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Send Challenge"])
{
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:@"I just scored %i points on this great game, called SumsUp. can you beat it?!", gameScore]
title:nil
parameters:nil
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error)
{
// Error launching the dialog or sending the request.
NSLog(@"Error sending request.");
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
// User clicked the "x" icon
NSLog(@"User canceled request.");
}
else
{
// Handle the send request callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"request"])
{
// User clicked the Cancel button
NSLog(@"User canceled request.");
}
else
{
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:@"request"];
NSLog(@"Request ID: %@", requestID);
}
}
}
}];
}
我在 P-List 中设置了自定义 url。
在我的应用委托中,我有:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
UIAlertView *alertView;
NSString *text = [NSString stringWithFormat: @"url recieved: %@", url];
alertView = [[UIAlertView alloc] initWithTitle:@"" message:text delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:[PFFacebookUtils session]];
}
我希望这是有道理的,有人可以帮助我。如果需要更多信息,请告诉我?
谢谢格雷厄姆