Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

troop231

macrumors 603
Original poster
Jan 20, 2010
5,826
561
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:
XzuSb.png


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];
        }
}
 
Last edited:
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:
Image

I appreciate any help offered.

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

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.
 
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];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.