2

I have used below code to open SnapChat and it only opens SnapChat from my app.

NSURL *appSnapChatURL = [NSURL URLWithString:@"snapchat://app"];
if([[UIApplication sharedApplication] canOpenURL:appSnapChatURL]) 
{
    [[UIApplication sharedApplication] openURL:appSnapChatURL];
}

Now I need one more functionality that how to add text/image/video in that so I can share text/image/video on SnapChat from my app.

Please help.

Asif Raza
  • 836
  • 12
  • 29
  • you can use UIActivityViewController in which you can pass video or image or text. That might help – Ali Farhan May 15 '17 at 07:18
  • Thanks, I attached image in below code then activity is showing SnapChat option... NSArray *objectsToShare = @[myImage]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; [self presentViewController:activityVC animated:YES completion:nil]; – Asif Raza May 15 '17 at 09:19
  • But when I am trying to attach a local video with code... NSString *filepath = [[NSBundle mainBundle] pathForResource:@"10Secs" ofType:@"mp4"]; NSURL *fileURL = [NSURL fileURLWithPath:filepath]; NSArray *objectsToShare = @[fileURL]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; [self presentViewController:activityVC animated:YES completion:nil]; then activity is not showing SnapChat option, please help. – Asif Raza May 15 '17 at 09:24
  • Can not share videos directly from UIActivityViewController to snapchat – Ali Farhan May 15 '17 at 09:37
  • http://stackoverflow.com/questions/28208980/video-not-attached-for-mail-when-sharing-video-using-uiactivityviewcontroller Try the way is getting the url of the video – Ali Farhan May 15 '17 at 09:44
  • If we can not share videos directly then how we can share videos to Snapchat. Please suggest. If any other way is possible. – Asif Raza May 15 '17 at 09:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144240/discussion-between-ali-farhan-and-asif-raza). – Ali Farhan May 15 '17 at 09:59

3 Answers3

0
NSArray *activityItems = [NSArray arrayWithObjects:[NSString stringWithFormat:@"Sample text", nil];
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

    [activityViewController setCompletionHandler:^(NSString *act, BOOL done)
     {
         //Code here for completion handler
     }];
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
       [self presentViewController:activityViewController animated:YES completion:nil];
    }
    //if iPad
    else {
        // Change Rect to position Popover
        UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
        [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
Ali Farhan
  • 199
  • 1
  • 8
  • Thanks again, I am doing same as above. I have successfully attached image and it shares to SnapChat but when I am trying to attach video then activity controller is not showing Snapchat option. – Asif Raza May 15 '17 at 09:51
  • My code is... -(void)showActivityWithURL:(NSURL *)url { NSArray *objectsToShare = [NSArray arrayWithObjects:url, nil]; //@[url]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; [self presentViewController:activityVC animated:YES completion:nil]; } Please help, how to attach video in activity. Or if possible, we can share video without using UIActivityViewController. Then it will be better. Thanks. – Asif Raza May 15 '17 at 09:51
  • Actually there is no api available to share the video directly to snapchat as per my knowledge because snapchat closed their developer portal back in 2015 – Ali Farhan May 15 '17 at 09:57
  • @AliFarhan but then how TicTok is able to do it? – Iraniya Naynesh Sep 10 '19 at 12:15
0

By using SCSDKCreativeKit --

   import SCSDKCreativeKit

  
   func shareToSnapchat(imageName: UIImage) {
    let stickerImage = imageName
    _ = SCSDKSnapSticker(stickerImage: stickerImage)
    let photo = SCSDKSnapPhoto(image: stickerImage)
    let photoContent = SCSDKPhotoSnapContent(snapPhoto: photo)
    
    photoContent.caption = "Anubhav Singh"
    photoContent.attachmentUrl = "https://twitter.com/anubhavpulkit"
    
    snapAPI.startSending(photoContent) { error in
        if let error = error {
            print(error.localizedDescription)
        } else {
            // success
        }}
    }
Anubhav Singh
  • 905
  • 6
  • 5
-1

Snapchat share in iOS, Swift. Please follow the tutorial below.

Snapchat Creative Kit iOS (Swift) - Image, Video, Sticker Sharing

emraz
  • 1,563
  • 20
  • 28