我想在URL方案的兩個應用程序之間進行應用程序間通信。我已經閱讀了Apple文檔,但不會得到太多幫助。如何使用URL方案傳輸文本或pdf文件
我做兩個項目,在發送端有我在其中添加
{
UIApplication *ourApplication = [UIApplication sharedApplication];
NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet];
NSString *URLEncodedText = [@"TEST" stringByAddingPercentEncodingWithAllowedCharacters:set];
NSString *ourPath = [@"readtext://" stringByAppendingString:URLEncodedText];
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL]) {
[ourApplication openURL:ourURL];
}
else {
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Receiver Not Found"
message:@"The Receiver App is not installed"
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
NSLog(@"RECEIVER NOT FOUND");
}
}
並且在接收器應用程序,添加以下代碼的應用程序委託一個方法
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet];
NSString *text = [[url host] stringByAddingPercentEncodingWithAllowedCharacters:set];
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Title"
message:text
preferredStyle:UIAlertControllerStyleAlert];
[self.window.rootViewController presentViewController:alert animated:YES completion:nil];
return YES;
}
還添加什麼的info.plist和Info下的URL類型。
請添加您嘗試過的來源示例。 – Sebastian
我已經嘗試下面的鏈接,對一些新的ios的更改 http://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629 – Verma
將此信息添加到您的問題(通過編輯)並顯示你改變了什麼。您可以輕鬆地將代碼複製並粘貼到問題編輯器中,突出顯示它並按{}圖標以將其顯示爲代碼。 – Sebastian