iOS (Objective-C) 的 ShareKit 替代品

ShareKit Alternatives for iOS (Objective-C)

我正在尝试升级一个旧应用,该应用使用 ShareKit 在 Facebook、Twitter、Google Plus 和 YouTube 上共享视频链接。

该应用使用 CocoaPods 作为依赖项,ShareKit 似乎不再有效。

如果有任何替代方法可以帮助我轻松设置所有这些社交网络共享而不是实现单独的 API,谁能指导我吗?

干杯。

您可以使用此功能分享文字、图片和 urls:

- (void)shareText:(NSString *)text andImage:(UIImage *)image andUrl:(NSURL *)url{
    NSMutableArray *sharingItems = [[NSMutableArray alloc] init];

    if (text) {
        [sharingItems addObject:text];
    }
    if (image) {
        [sharingItems addObject:image];
    }
    if (url) {
        [sharingItems addObject:url];
    }

    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];

    //need for iPads. Add subview in bottom to set the start to share view
    CGRect mainFrame = [[UIApplication sharedApplication].keyWindow.rootViewController view].frame;
    UIView *sourceView = [[UIView alloc] initWithFrame: CGRectMake(mainFrame.size.width/2, mainFrame.size.height, 0, 0)];
    [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:sourceView];
    activityController.popoverPresentationController.sourceView = sourceView;

    // Present share view
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:activityController animated:YES completion:nil];
}

使用示例

[self shareText:nil andImage:nil andUrl: yourUrl]

这只会分享您的 url。

结果