Resolved iOS 6 not posting image to Facebook via UIActivity

Discussion in 'iOS Programming' started by troop231, Oct 7, 2012.

  1. troop231, Oct 7, 2012
    Last edited: Oct 7, 2012

    troop231 macrumors 603

    Joined:
    Jan 20, 2010
    #1
    My console throws this error when attaching an image to send via Facebook:

    Code:
    <Error>: CGImageCreate: invalid image size: 0 x 0.
    The same image works fine while sending to Twitter also via UIActivity. The Facebook image doesn't work on the device or the simulator, and shows a safari type icon.

    Pic of issue:
    [​IMG]

    I appreciate any help offered.

    EDIT: The issue only happens when I attach a url along with the image.

    Here is my code:
    Code:
    - (void)test
    {
        NSString *textItem = @"Check out the app:";
        UIImage *imageToShare = [UIImage imageNamed:@"test.png"];
        NSURL *url = [NSURL URLWithString:@"http://applinkhere"];
                        
        CustomProvider *customProvider =
                        [[CustomProvider alloc]init];
                        NSArray *items = [NSArray arrayWithObjects:customProvider,textItem,imageToShare,url,nil];
                        
        CustomActivity *ca = [[CustomActivity alloc]init];
                        UIActivityViewController *activityVC =
                        [[UIActivityViewController alloc] initWithActivityItems:items
                                                          applicationActivities:[NSArray arrayWithObject:ca]];
                        
     activityVC.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeSaveToCameraRoll];
                        
     activityVC.completionHandler = ^(NSString *activityType, BOOL completed)
     {
                            NSLog(@" activityType: %@", activityType);
                            NSLog(@" completed: %i", completed);
     };
                        
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
     {
           self.popoverController = [[UIPopoverController alloc] initWithContentViewController:activityVC];
                            
           CGRect rect = [[UIScreen mainScreen] bounds];
    
           [self.popoverController
           presentPopoverFromRect:rect inView:self.view
           permittedArrowDirections:0
           animated:YES];
     }
     else
           {
                [self presentViewController:activityVC animated:YES completion:nil];
            }
    }
    
     
  2. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #2
    A suggestion for your post: Don't call the class you're using "UIActivity". There is no class in iOS with that name. Looking at your code I can tell that you're using the new-to-iOS-6 class UIActivityViewController.

    I would suggest using the full UIActivityViewController class name in your post title, and also indicate that it's a new iOS 6 framework. If you do that you're more likely to attract the attention of somebody who's used that class.

    My business partner is the social media expert for our company. He's written a social media wrapper that offers the same function in iOS 5 and 6, and I use that. Thus, I can't offer any help with using UIActivityViewController.
     
  3. troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #3
    Problem solved!

    It appears it that Twitter and FB both handle the url formatting, and this works:

    Code:
    NSString *textItem = @"Check out the yourappnamehere app: http://itunes.apple.com/us/app/yourapplink";
                        UIImage *imageToShare = [UIImage imageNamed:@"someimage.png"];
    
    CustomProvider *customProvider =
                        [[CustomProvider alloc]init];
                        NSArray *items = [NSArray arrayWithObjects:customProvider,textItem,imageToShare,nil];
                        
                        CustomActivity *ca = [[CustomActivity alloc]init];
                        
                        UIActivityViewController *activityVC =
                        [[UIActivityViewController alloc] initWithActivityItems:items
                                                          applicationActivities:[NSArray arrayWithObject:ca]];
                        
                        activityVC.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeSaveToCameraRoll];
    
    
     

Share This Page