3

I am using an UIActivityViewController to show share options. The information I am trying to share consists of two pieces (a plain string and an url). The share is working through all the extensions like iMessages, Mail, Notes, Twitter, Facebook etc, but the app is crashing when I try to share through Slack. The weird thing is that the crash only happens if I am not debugging and it never crashes while debugging.

Code:

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[title, self] applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];

# UIActivityItemSource methods
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
    return url;
}

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
    return url;
}

- (NSString*)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType {
    return title;
}

- (NSString *)activityViewController:(UIActivityViewController *)activityViewController dataTypeIdentifierForActivityType:(NSString *)activityType {
    return @"com.test.url";
}

- (UIImage *)activityViewController:(UIActivityViewController *)activityViewController thumbnailImageForActivityType:(NSString *)activityType suggestedSize:(CGSize)size {
    return image;
}

I also noticed that this crash is happening on the Flipboard app and it's working fine on the Twitter app.

Did anyone run into this issue? If so can you please let me know what's the issue and how this can be fixed?

Ashok
  • 5,585
  • 5
  • 52
  • 80
kans
  • 51
  • 8
  • Do I need to add some kind of key to the Info.plist for the slack share to work properly? – kans Nov 16 '17 at 21:46
  • 2
    I'm having the same issue.. Seems to be a bug within the Slack extension... – tperei Nov 17 '17 at 18:25
  • @HeavenlyManBR Can you try the solution I posted below and see if that works? It seems to be working for me. – kans Nov 18 '17 at 20:10
  • Getting the same issue. My app is getting crashed when sharing via slack, not getting it always, but it's happening frequently. All the other apps are working fine. – Ashok Apr 05 '18 at 07:32
  • Sent feedback to Slack team on AppStore through a review :) https://gist.github.com/ashokkumarmw/fe93b1f834f07b5cbda7dd25b01ce9df – Ashok Apr 05 '18 at 07:40

2 Answers2

4

I've recently run into what sounds like the same issue. Sharing with Slack won't crash when you only have one item in the activityItems/initWithActivityItems array, but if you have more than that, it will crash. I don't know if you are experiencing that particular problem, but a workaround is to combine the url and text into one string object, if that will fit your use case. Seems like a problem with Slack that they need to address.

grouchcan
  • 41
  • 2
  • Great, thanks for the quick response. Yeah, it is an issue when you have more than one item in the activityItems/initWithActivityItems array. I tried combining the url and text into one string object too. It work's fine with slack using that approach, but for other types of share like twitter the share output is not what I am expecting to see. While I am expecting to see a thumbnail image and the title for that article with an url below it all in a rounded box, it's not showing that stuff in the share window. Not sure how I can post images here. – kans Nov 17 '17 at 15:34
0

This worked for me. Created a class for UIActivityItemSource. Instead of passing in self to the activityItems/initWithActivityItems array, I just passed in the itemSource.

ActivityItemSource *itemSource = [[ActivityItemSource alloc] initWithTitle:title url:url thumbnail:thumbnail];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[title, itemSource] applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];

ActivityItemSource.m

@interface ActivityItemSource() <UIActivityItemSource>

@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSURL *url;
@property (strong, nonatomic) UIImage *thumbnail;
@end

@implementation ActivityItemSource

- (instancetype)initWithTitle:(NSString *)title url:(NSURL *)url thumbnail:(UIImage *)thumbnail {
    self = [self init];
    if (self) {
        self.title = title;
        self.url = url;
        self.thumbnail = thumbnail;
    }

    return self;
}

- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
    return self.url;
}

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
    return self.url;
}

- (NSString*)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType {
    return self.title;
}

- (UIImage *) activityViewController:(UIActivityViewController *)activityViewController thumbnailImageForActivityType:(NSString *)activityType suggestedSize:(CGSize)size {
    return self.thumbnail;
}

@end
kans
  • 51
  • 8
  • 1
    I take it back, this looked it worked on that day when I made this change. But this crash is still happening. – kans Nov 22 '17 at 16:06