Search code examples
iphonexcodeimagemms

Attach image in MMS / Facebook from iPhone.


I've easily found a way to post a picture to twitter, and email below.. But I still can't find a solution for MMS, all the searches on here say it's not possible but those posts are over a year old.. If anyone knows please help..

TWEET PICTURE

-(IBAction)tweetpicture...{
    TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
    [twitter setInitialText:@""];
    [twitter addImage:tweetimage.image];
    [self presentViewController:twitter animated:YES completion:nil]; 
    [self dismissModalViewControllerAnimated:YES];
}

EMAIL PICTURE

-(IBAction)mailpicture....{
    MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
    [mailComposer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
       // [mailComposer setToRecipients:[NSArray arrayWithObjects:@"", nil]];
        [mailComposer setSubject:@""];
        [mailComposer setMessageBody:@"" isHTML:NO];
        [mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        UIImage *xcode = mailimage.image;
        NSData *xcodeData = UIImagePNGRepresentation(xcode);
        [mailComposer addAttachmentData:xcodeData mimeType:@"image/png" fileName:@""];
        [self presentModalViewController:mailComposer animated:YES]; 
        [mailComposer release]; 

    } else { 
        [mailComposer release]; 
    }
}

MMS PICTURE

-(IBAction)sendviatext...{
    //???
}

FACEBOOK PICTURE

-(IBAction)sendtofacebook...{
    ???
}

Solution

  • First of you can't send an MMS from code in iOS, only SMS is supported.

    And facebook I did something like:

    Facebook *facebook = [App instance].facebook;
    
    
        if ([facebook isSessionValid]) {
    
            NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                           self.capturedImage.image, @"picture",
                                           @"Some nice caption", @"caption",
                                           nil];
    
            [facebook requestWithMethodName:@"photos.upload"
                                   andParams:params
                               andHttpMethod:@"POST"
                                 andDelegate:self];
        } else {
            [facebook authorize:[NSArray arrayWithObjects:@"offline_access", nil]];
        }