iosobjective-csharekit

ShareKit Alternatives for iOS (Objective-C)


I'm trying to upgrade an old app that was using ShareKit to share video links on Facebook, Twitter, Google Plus and YouTube.

The app uses CocoaPods for dependencies and ShareKit doesn't seem to work anymore.

Can anyone guide me here if there are any alternatives out there that would help me setup all those social network sharing easily instead of implementing separate APIs?

Cheers.


Solution

  • You can share text, images and urls using this function:

    - (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];
    }
    

    Usage example

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

    This will share only your url.

    Result

    shareText result