0

我知道它可以通过交互控制器传递文件。但是有没有办法将纯文本(字符串)传递给另一个应用程序,比如“Open in..”?我知道安卓可以做到。但是iOS呢?

编辑:我不想在自定义应用程序中打开处理我的字符串。我想在那些支持整个系统中的字符串处理的应用程序中打开。

4

2 回答 2

1

在应用程序-A 中执行以下 2 个步骤:

步骤1:

  • 打开左侧的“支持文件”(文件夹),然后单击“YourAppName-Info.plist”
  • 选择“Bundle creator OS Type Code”之类的行并将鼠标悬停在行上并单击(+)符号这将创建一个新行并输入“URL types”
  • 单击左侧的箭头并查看 Item 0,您将 Item 0 中的值重命名为“URL Schemes”,如图所示
  • 然后编辑项目 0 中的字段并输入“testURLScheme”在此处输入图像描述

Step-2:在同一个应用程序中添加这个 URL 回调方法,

 - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{

        if ([url.scheme caseInsensitiveCompare: @"testURLScheme"]==NSOrderedSame){
            NSArray *params = [url.query componentsSeparatedByString:@"&"];
            NSArray *paramNameAndValue = [params[0] componentsSeparatedByString: @"="];
        }
    }

在 application-B 中执行此操作,调用以下代码:

NSString *stringURL = @"testURLScheme://optionalAdress?paramName=stringToSend";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
于 2013-09-13T08:57:50.957 回答
0

为此使用自定义 URL。在您的应用中,您调用:

NSURL *myURL = [NSURL URLWithString:@"yourcustomurl://?param1=value&param2=value2"];
[[UIApplication sharedApplication] openURL:myURL];

在必须处理参数的应用程序上,您可以在此处获取:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 
{
    //depending of your format you can get them from one of NSURL methods:
    NSString *urlString = [url absoluteString];
    NSString *parameters = [url parameterString];
    NSString *query = [url query];
}

阅读更多:

https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW50

于 2013-09-13T08:33:26.477 回答