我们正在尝试对两个应用程序使用应用程序间通信,并尝试将文件路径从一个应用程序发送到另一个应用程序,问题是如果我通过发送方应用程序将任何文本传递给接收方,那么它运行良好,但如果我尝试通过文件文档路径然后它在这里不起作用是我的发件人代码
-(IBAction) openReceiverApp:(id)sender {
// Opens the Receiver app if installed, otherwise displays an error
UIApplication *ourApplication = [UIApplication sharedApplication];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"ads.rtf"];
NSLog(@"filePath %@", filePath);
// NSString *URLEncodedText = [self.textBox.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *URLEncodedText = [filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *ourPath = [@"readtext://" stringByAppendingString:URLEncodedText];
NSLog(@"%@",ourPath);
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL]) {
[ourApplication openURL:ourURL];
}
else {
//Display error
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Receiver Not Found" message:@"The Receiver App is not installed. It must be installed to send text." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
在接收方我写了这段代码
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// Display text
UIAlertView *alertView;
NSString *text = [[url host]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
alertView = [[UIAlertView alloc] initWithTitle:@"Text" message:text delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
return YES;
我哪里错了??提前致谢....