Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble getting custom activities like TUSafariActivity to work #12

Open
simonbromberg opened this issue Jul 22, 2014 · 1 comment
Open

Comments

@simonbromberg
Copy link

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];
}
@simonbromberg
Copy link
Author

Setting the placeholder to nil and forcing TUSafariActivity's canPerormWithActivityItems to always return YES seems to work, but this isn't an ideal solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant