Skip to content

Trouble getting custom activities like TUSafariActivity to work #12

@simonbromberg

Description

@simonbromberg

In TUSafariActivity.m there's an implementation of "canPerformWithActivityItems:(NSArray *)activityItems" that looks for an URL in the activity items. But using the method in the README here, the RDActivityViewController just passes an array of itself repeated according to the maximum number of items passed in the init method... So this method always returns NO and it won't load that activity item. It does work if I replace "self" with "placeholderItem". So why does it pass self?

- (id)initWithDelegate:(id)delegate maximumNumberOfItems:(int)maximumNumberOfItems applicationActivities:(NSArray *)applicationActivities placeholderItem:(id)placeholderItem {
 ...
     [items addObject:self];
 ...

But also if I replace self with placeholderItem, the link that the activity uses is the placeholder item... Doesn't seem to be calling activityViewController: itemsForActivityType for the TUSafariActivity.

Also for some reason it doesn't show Facebook or Twitter when I do get the TUSafariActivity to show.

Also depending on how I have it set up, it seems to crash (bad access) when I present the activity view controller.

Code:

-(void) share {
    TUSafariActivity* safariActivity = [TUSafariActivity new];
    RDActivityViewController* shareDrawer = [[RDActivityViewController alloc] initWithDelegate:self maximumNumberOfItems:3 applicationActivities:@[safariActivity] placeholderItem:[NSURL URLWithString:@"http://google.com"]];
    shareDrawer.excludedActivityTypes = @[UIActivityTypePostToWeibo,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypePrint];

    shareDrawer.completionHandler = ^(NSString *activityType, BOOL completed){
        if (completed) {
            NSLog(@"Selected activity was performed.");
        } else {
            if (activityType == NULL) {
                NSLog(@"User dismissed the view controller without making a selection.");
            } else {
                NSLog(@"Activity was not performed.");
            }
        }
    [self presentViewController:shareDrawer animated:YES completion:nil];
}

-(NSArray*) activityViewController:(NSArray *)activityViewController itemsForActivityType:(NSString *)activityType {
    NSURL* url = [self shareURL];
    NSString* text = [self shareText];
    UIImage* image = self.eventImage.image;
    if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
        return @[text,url,image];
    }

    if ([activityType isEqualToString:UIActivityTypeCopyToPasteboard]) {
        return @[url];
    }
    if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
        return @[text,url];
    }

    if ([activityType isEqualToString:TUSafariActivityType]) {
        return @[url];
    }

    return @[text,url,image];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions