【问题标题】:how to send file from from one app to another app using url scheme?如何使用 url 方案将文件从一个应用程序发送到另一个应用程序?
【发布时间】:2015-12-18 05:44:56
【问题描述】:

总结(iOS 8、Xcode 6.4)

第一个问题:- 我可以与我的其他应用共享我的应用的文档目录的数据吗?

如果是,我已经看到很多与此相关的问题; Move data/images between two iOS apps using custom URL handler, http://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629

但我发现这些示例只发送文本或 URL。然后我自己尝试如下:

NSString* path = [NSString stringWithFormat:@"MY_URL_SCHEME://"];
NSURL* url = [NSURL URLWithString:path];
if([[UIApplication sharedApplication]canOpenURL:url]) {
    [[UIApplication sharedApplication]openURL:url];
}

上面的代码可以很好地打开我的其他应用程序。但是当我像下面这样尝试时,我无法打开我的其他应用程序。

NSArray* mainPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *sourcePath = [mainPath objectAtIndex:0];
NSString* path = [NSString stringWithFormat:@"MY_URL_SCHEME://%@",sourcePath];
NSURL* url = [NSURL fileURLWithPath:path isDirectory:YES];
if([[UIApplication sharedApplication]canOpenURL:url]) {
    [[UIApplication sharedApplication]openURL:url];
}

那么,请帮帮我,我错过了什么?
编辑:-
我忘了提,iOS7 支持在我的 App 中很重要。所以,我认为扩展可能不起作用。

【问题讨论】:

  • 真的需要为此使用 URL 方案吗?听起来它作为扩展可能会更好。见developer.apple.com/library/ios/documentation/General/…
  • @SteveWilford,实际上,我只想将一些数据从一个应用程序发送到另一个应用程序。方式无关紧要。顺便说一下,让我试试你的建议。
  • 如果您控制这两个应用程序并根据要求设置它们,您可以创建一个应用程序组,允许您共享一个公共文件系统。请参阅this questionthis blogApple Docs
  • 我只是想发送一些数据,你可以为那个文件/数据使用base64编码的字符串

标签: ios objective-c xcode6 url-scheme


【解决方案1】:

您可以参考 MGInstagram 文件,因为 Instagram 移动应用程序的工作方式相同。您可以将图像从您的应用程序传递到 Instagram 应用程序。

您可以从这里下载:https://github.com/mglagola/MGInstagram

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    使用 NSUserDefaults 和应用组在应用之间共享数据

    NSUserDefaults *defaults=[[NSUserDefaults 
    alloc]initWithSuiteName:@"app group name"];
    [defaults setObject:filedata forKey:@"keyfordata"];
    [defaults synchronize];
    

    在消费应用的应用委托中从NSUserDefaults获取数据

    另一种方法是使用共享扩展- http://easynativeextensions.com/how-to-launch-your-app-from-the-ios-8-share-menu/

    【讨论】:

      猜你喜欢
      • 2016-02-03
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多