【问题标题】:How to place iOS Share Facebook and Instagram Share buttons in one place? [closed]如何将 iOS Share Facebook 和 Instagram Share 按钮放在一个地方? [关闭]
【发布时间】:2016-01-22 13:14:19
【问题描述】:

我有一个分享图片的应用。我已经尝试过 Social Framework 并且 UIActivity 工作正常。但我想要的是把 Facebook 和 Instagram 放在一个地方,我找不到办法。找了很多,有没有办法?

【问题讨论】:

    标签: ios objective-c facebook share instagram


    【解决方案1】:

    更改文件类型:

    - (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、instagram 和 WhatsApp。

    只显示选定选项的问题仍未解决,但这是次要问题。

    【讨论】:

    • 是否可以将 Facebook 分享放入 UIDocumentInteractionController?所以它显示在同一个地方
    • Facebook 的 UTI 是什么?你能输入 Instagram 和 Facebook 的代码吗?
    • 你能试试我的代码吗?
    • 如果工作则接受为答案
    • 如果有任何问题..continue this discussion in chat.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多