2

画像の共有オプションとして Facebook と WhatsApp が必要です。私はすでに UIActivityViewController を実装しており、Facebook 経由UIDocumentInteractionControllerで共有でき、WhatsApp 経由で共有できます。これらのものをマージする方法がわかりません。

UIActivityViewController:

UIActivityViewController *activityViewContoller = [[UIActivityViewController alloc] 
       initWithActivityItems:@[@"Test", image] applicationActivities:nil];
[self presentViewController:activityViewContoller animated:YES completion:nil];

UIDocumentInteractionController:

NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];
    [UIImageJPEGRepresentation(image, 1.0) writeToFile:savePath atomically:YES];

    _documentInteractionController = [UIDocumentInteractionController 
                 interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _documentInteractionController.UTI = @"net.whatsapp.image";
    _documentInteractionController.delegate = self;
    [_documentInteractionController presentOpenInMenuFromRect:CGRectZero 
                                    inView:self.view animated:YES];

両方を1つのポップオーバーに入れたいのですが、それを達成する方法がわかりません。ヒントをお願いします。

StackOverFlow question 1を確認しましたが、まったく役に立ちません。私のファイルは .wai (WhatsApp 用) なので、FB 経由で送信しようとすると、ファイルを開くことができません。また、すべてのオプションが表示されますが、2つ(FB + WhatsApp)のみを表示したいです。StackOverFlowの質問2に続いて、FBのみを表示できます(通常の画像を設定したため、動作中のものです)が、WhatsAppを追加できません(.waiファイルがなく、UTIをどうするかわかりません)。この問題を解決する方法はありますか?

4

2 に答える 2

4

ファイルの種類を変更するには:

- (void)share {
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/tmptmpimg.jpg"];
    [UIImageJPEGRepresentation(_img, 1.0) writeToFile:path atomically:YES];

    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
    _documentInteractionController.delegate = self;
    [_documentInteractionController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];
}

- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
    if ([self isWhatsApplication:application]) {
        NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/tmptmpimg.wai"];
        [UIImageJPEGRepresentation(_img, 1.0) writeToFile:savePath atomically:YES];
        controller.URL = [NSURL fileURLWithPath:savePath];
        controller.UTI = @"net.whatsapp.image";
    }
}

- (BOOL)isWhatsApplication:(NSString *)application {
    if ([application rangeOfString:@"whats"].location == NSNotFound) { // unfortunately, no other way...
         return NO;
    } else {
         return YES;
    }
}

このようにして、Facebook、Twitter、カスタム WhatsApp などのすべてのオプションを使用できます。

選択したオプションのみを表示する問題はまだ解決されていませんが、マイナーなものです。

于 2014-01-02T16:29:35.230 に答える
0

UIActivityViewController望ましくない共有オプション (質問の 2 番目の部分) を除外するには、オブジェクトが呼び出されていると仮定して、次activityControllerのように excludedActivityTypes プロパティを設定します。

activityController.excludedActivityTypes = @[UIActivityTypeAssignToContact,
                                                 UIActivityTypePrint,
                                                 UIActivityTypeAddToReadingList,
                                                 UIActivityTypeAirDrop];
于 2014-05-21T05:25:27.327 に答える