我想打开一个应用程序并从它返回一些返回值,如成功或失败。怎么做?
从文档
[scheme]://[host]/[action]?[x-callback parameters]&[action parameters]
问题一:
我应该在 [动作参数] 中放置什么?是强制性的吗?
发送应用程序 A
- (IBAction)openReceivingAppBButtonPressed:(id)sender {
NSString *xcallBack = @"x-callback-url/payment?&amount=1.00";
NSString *URLEncodedText = [xcallBack stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *ourURL = [NSURL URLWithString:[@"receivingAppB://" stringByAppendingString:URLEncodedText]];
if([[UIApplication sharedApplication] canOpenURL:ourURL]){
[[UIApplication sharedApplication] openURL:ourURL];
}
}
接收应用程序 B
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
[self returnToSendingAppAWithResponse];
return true;
}
-(void)returnToSendingAppAWithResponse{
NSString *xcallBackSuccess = @"success";
NSString *URLEncodedText = [xcallBackSuccess stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *ourURL = [NSURL URLWithString:[@"sendingAppA://" stringByAppendingString:URLEncodedText]];
if([[UIApplication sharedApplication] canOpenURL:ourURL]){
[[UIApplication sharedApplication] openURL:ourURL];
}
}
问题2:
在接收应用程序中,对发送应用程序 A 调用另一个 openURL 调用以返回成功消息是否正确?
我能够实现我想要的。但是只是怀疑这是否是使用 x-callback-url 的正确方法。x-callback-url 似乎对我没有用。