8

グーグルでSOをしばらく検索した後、私はまだ答えを見つけることができませんでした-

カスタム URL ハンドラーを使用して、2 つのアプリ間でデータを転送するにはどうすればよいでしょうか? 具体的には、画像または NSData オブジェクトです。

myapp1://start 、 myapp2://start などのカスタム ハンドラーを使用してアプリの特定の部分を開くことができることは知っていますが、これらを介して大量のデータ (~80k) を転送する方法がわかりません。ハンドラー。

創造的な解決策を聞きたいです:)

psソリューションは iOS >= 4.3 互換である必要があります

4

5 に答える 5

11

カスタム URL ハンドラーを UIPasteboard と組み合わせて使用​​します。次のように、最初のアプリから何か (画像など) を一般的なペーストボードに保存します。

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[[UIPasteboard generalPasteboard] setImage:myImage];

次に、カスタム URL スキームを使用してアプリを切り替えます。

次に、必要なときに新しいアプリ内から画像を取得します。

   UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
   UIImage *tempImg = pasteboard.image;

バトルテスト済み。; )

于 2012-09-08T23:01:47.000 に答える
3

1つの解決策は次のとおりです。

  • ウェブサーバーを実装する
  • URL に含まれるカスタム Web サーバーの IP アドレスとポートを使用して、カスタム URL スキームを介して 2 番目のアプリを開きます。
  • ルートまたはパラメーターを画像に追加し、URL にも追加します

写真をダウンロードしてお楽しみください :-)

別の解決策:

  • Bonjour サービスを開始する
  • ネットワークでは、2 番目のアプリがこのサービスを見つけることができます
  • アプリ間でデータを渡すためにいくつかの魔法を行います

編集:より良い他の解決策:

別の、しかしより大きなデータセットの交換を行うためのはるかに効率的な方法を見つけました
UIPasteboard

そのための最良のリファレンス:
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIPasteboard_Class/Reference.html

そして別のリソース:
http://kmithi.blogspot.in/2012/03/sharing-data-among-ios-applications.html

それはそれを行う必要があります。ウェブサーバーの場合: Google を使用して見つかった実装がたくさんあります

于 2012-09-08T14:03:48.587 に答える
1
     [http://www.codeproject.com/Articles/43447/How-to-Use-UIPasteBoard-to-Implement-Custom-Copy-a][1]

        As you know many of the controls in UIKit now come pre-loaded with the ability to copy and paste text. You can also use this new ability in your own apps to copy and paste other things including: images, SQLite databases, text or any file. This is a great way to share data between your apps if you want to provide users with a suite of apps with integrated functionality.



     CopyFrom Source Code
        -(IBAction)copyImageToPasteBoard{
            UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyFrom" 
                     create:YES];
            appPasteBoard.persistent = YES;

            NSData *data = UIImagePNGRepresentation([UIImage imageNamed:@"Old-Time-Photo.jpg"]);
            [appPasteBoard setData:data forPasteboardType:@"com.appshop.copyfrom.imagedata"];
        }

        -(IBAction)copyStringToPasteBoard{
            UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyFrom" 
                     create:YES];
            appPasteBoard.persistent = YES;
            [appPasteBoard setString:textView.text];
        }
        PasteTo Source Code
        -(IBAction)pasteImageToPasteBoard{
            UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyFrom"
                     create:YES];
            NSData *data = [appPasteBoard dataForPasteboardType:@"com.appshop.copyfrom.imagedata"];
            imageView.image = [UIImage imageWithData:data];
        }

        -(IBAction)pasteStringToPasteBoard{
            UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyFrom" 
                     create:YES];
            textView.text = [appPasteBoard string];
        }


    Using UIPasteBoard in iPhone programming is amazingly simple and opens up some possibilities that we did not have a year ago. To use UIPasteBoard you simply create a instance using pasteboardWithName, put stuff into the paste board and then set the persistant property equal to YES. Then any app can get a reference to your paste board and use the data contained within. You can use it for simple strings and even data that you can put into NSData like SQLite databases.
于 2014-05-13T06:48:02.290 に答える
0

カスタムURLハンドラーを使用する

指定されているため、仕様に適合しません。

しかし、それを気にしないのであれば、80Mbであっても、内部メモリ(ファイルシステム)に80kイメージを書き込み、他のアプリの「url」を渡します。

大きな自我、そして研究における0の努力:

画像フォルダにコピー

URLを介したIPC通信

そして私の解決策はうまくいきません...私は魚を与えていません、ただ魚を手に入れるために熱く教えています。

于 2012-09-08T14:00:45.797 に答える
0

私が知る限り、カスタム URL ハンドラーには 80k は多すぎます。ただし、データを Base64 エンコードしてカスタム URL に追加することもできます。しかし、それが多くのデータで機能するとは思えません。

UIDocumentInteractionControllerまた、ファイルをサポートする他のアプリケーションでファイルを開くことを目的とした を参照することもできます。これは、別のアプリで添付ファイルを開くときにメール アプリケーションが行うことです。

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html#//apple_ref/doc/uid/TP40009304

于 2012-09-08T14:21:29.680 に答える