I want to send message with image data. So I used MFMessageComposeViewController.
But that controller provide only SMS service. So I used UIPasteBoard attached an image data.
But It doesn't work, either. There are no "Paste" button created when typing messages. Attaching image at UIPasteBoard was clearly success.
I think using MFMessageComposeViewController doesn't solve my problem.
How can I accomplish my goal?
This is not possible with the current MessageUI API: the MSMessageComposeViewController doesn't accept attachments like the MFMailComposeViewController does.
The only way to do this currently is to use an external service that allows you to send mms via a REST call for example.
GSMA defines a REST specification for exactly this purpose:
http://www.gsmworld.com/oneapi/reference_documentation-version_1.html (multiple pdf's on this page)
Try to find a local service provider that implements this specification and you're good to go.
Just to add the direct wiki link to the OneAPI MMS spec: http://gsma.securespsite.com/access/Access%20API%20Wiki/MMS%20RESTful%20API.aspx and a link to the PHP/Java sandbox https://github.com/OneAPI/GSMA-OneAPI where MMS can be tested locally . Cheers.
Here is the correct working code and it is working perfectly on my device.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = NO;
NSMutableDictionary *text = [NSMutableDictionary dictionaryWithCapacity:1];
[text setValue:label.text forKey:(NSString *)kUTTypeUTF8PlainText];
NSMutableDictionary *image = [NSMutableDictionary dictionaryWithCapacity:1];
[image setValue:imageView.image forKey:(NSString *)kUTTypePNG];
pasteboard.items = [NSArray arrayWithObjects:image,text, nil];
NSString *phoneToCall = #"sms:";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
I had the same question that I posted here. There is a bug in MFMessageComposeViewController and if you just use the code below it will launch a message that you can insert images into
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
This Method is tested and verified. I Used it in my code.
if (![MFMessageComposeViewController canSendText]) {
UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device not support SMS \nOr you hadn't login your iMessage" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alertV show];
return;
}
MFMessageComposeViewController *mVC = [[MFMessageComposeViewController alloc] init];
mVC.body = #"jjjj";
mVC.recipients = #[#"00XXXXXXXXXX"];
mVC.messageComposeDelegate = self;
if ([MFMessageComposeViewController canSendAttachments]) {
NSLog(#"ok");
}
[mVC addAttachmentData: UIImageJPEGRepresentation([UIImage imageNamed:#"test.jpg"], 1.0) typeIdentifier:#"public.data" filename:#"image.jpeg"];
[self presentViewController:mVC animated:YES completion:nil];
You can use any jpeg jpg and png formats.
Swift way. Works in iOS11
func shareViaMessage() {
if !MFMessageComposeViewController.canSendText() {
showAlert("Text services are not available")
return
}
let textComposer = MFMessageComposeViewController()
textComposer.messageComposeDelegate = self
textComposer.body = "Try my #app"
if MFMessageComposeViewController.canSendSubject() {
textComposer.subject = "AppName"
}
if MFMessageComposeViewController.canSendAttachments() {
let imageData = UIImageJPEGRepresentation(imageView.image!, 1.0)
textComposer.addAttachmentData(imageData!, typeIdentifier: "image/jpg", filename: "photo.jpg")
}
present(textComposer, animated: true)
}
Why don't you share the Image and Text via the Share API (selecting Message, and if you want exluding Facebook, twitter etc..)
Related
I used following code, and instagram app displays my photo but text what I want to share dosen't display.
I used annotation property, but it's not working. I don't know where is wrong ?
instagram version : 3.5.0
my iphone version : 5.0.1
xcode version : 4.6
Regards.
NSURL *instagramURL = [NSURL URLWithString:#"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/image.igo"];
NSString *urlString = [[NSString alloc] initWithFormat:#"file://%#", jpgPath];
NSURL *imageUrl = [[NSURL alloc] initWithString: urlString];
self.docController = [self setupControllerWithURL:imageUrl usingDelegate:self];
self.docController.UTI = #"com.instagram.exclusivegram";
self.docController.annotation = [NSDictionary dictionaryWithObject:#"I want to share this text" forKey:#"InstagramCaption"];
[self.docController presentOpenInMenuFromRect: self.view.frame inView: self.view animated: YES ];
}
According to the Instagram forum, 3rd party captions broke in the latest (3.5) release.
https://groups.google.com/d/topic/instagram-api-developers/wLfX0cJUUyM/discussion
See the following comment from Mike Krieger acknowledging the bug:
https://groups.google.com/d/msg/instagram-api-developers/wLfX0cJUUyM/SK_m4IJ3wn8J
In my App I sharing an image on Instagram. It is working well in my app.
I am using the following code.
#property (nonatomic, retain) UIDocumentInteractionController *dic;
CGRect rect = CGRectMake(0 ,0 , 0, 0);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/test.igo"];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"file://%#", jpgPath]];
// NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"file://%#", screenshot]];
self.dic.UTI = #"com.instagram.photo";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self.dic presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}
Now I also want to share some text with the image.
As shown in the Image below. In " Write a Caption", I want some default custom text for eg. "Share this photo".
How can I do this?
Thanks in advance...
Edited
I am opening Instagram from my app for sharing images and it works fine.
But Is it possible that Can I check Whether the user has shared it successfully or not?
Means I want to perform some action in my DB when user successfully shares an image.
How can i do this?
I got my answer. Just added a line and it worked for me.
self.dic.annotation = [NSDictionary dictionaryWithObject:#"Here Give what you want to share" forKey:#"InstagramCaption"];
Thanks...
It is also documented in the official documentation at http://instagram.com/developer/iphone-hooks/
To include a pre-filled caption with your photo, you can set the annotation property on the document interaction request to an NSDictionary containing an NSString under the key "InstagramCaption". Note: this feature will be available on Instagram 2.1 and later.
You are no more allowed to share Pre-Filled Text with Instagram or Facebook.
Only Images/Screenshots can be shared via UIDocumentInteractionController.
An app that I am developing relies on the ability to help users send a mixture of images and text to their friends in one go.
I was hoping that MFMessageComposeViewController would offer some way to provide the user with an image in the body of the message, but evidently I can only suggest NSString for the body.
Alternatively, I could render the text into the image and then send that as well, but I still haven't found a way to suggest that the user send an image via MMS.
Is there a way to do either of these things?
I had the same troubles with sending MMS.
I resolved it in this way:
[UIPasteboard generalPasteboard].image = yourImage;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"sms:"]];
So firstly I copied needed image to clipboard and then open standard
MFMessageComposeViewController and paste this image from clipboard.
And of course You should have suitable settings for MMS on your phone.
i think, you should use below code. because by default image type is jpeg for png images are not showing in iMessage when you try to paste.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"aa1" ofType:#"png"]];
[pasteboard setData:data forPasteboardType:#"public.png"];
// or if image is jpeg then below code
[pasteboard setData:data forPasteboardType:#"public.jpeg"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"sms:45263125"]];
We cannot send MMS via iOS native SDK.
However we can iMessage a picture to a contact
This Method is tested and verified. I Used it in my code.
if (![MFMessageComposeViewController canSendText]) {
UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device not support SMS \nOr you
hadn't login your iMessage" delegate:nil cancelButtonTitle:#"Ok"
otherButtonTitles:nil, nil];
[alertV show];
return;
}
MFMessageComposeViewController *mVC = [[MFMessageComposeViewController alloc] init];
mVC.body = #"jjjj";
mVC.recipients = #[#"00XXXXXXXXXX"];
mVC.messageComposeDelegate = self;
if ([MFMessageComposeViewController canSendAttachments]) {
NSLog(#"ok");
}
[mVC addAttachmentData: UIImageJPEGRepresentation([UIImage imageNamed:#"test.jpg"], 1.0) typeIdentifier:#"public.data"
filename:#"image.jpeg"];
[self presentViewController:mVC animated:YES completion:nil];
You can use any jpeg jpg and png formats.
No, you can't send MMS using the iOS SDK.
You can however send both text and images via email using MFMailComposeViewController.
Below is the method I'm using with Sharekit to send an image and a title to facebook. I also want to send a URL along with the facebook post. If I try
SHKItem *item = [SHKItem image:image url:url title:titleString];
I get a too many arguments error message. Does anyone have any ideas on how this should be done? thanks for any help.
- (IBAction)myButtonHandlerAction
{
NSURL *url = [NSURL URLWithString:#"http://example.com/"];
NSString *titleString = [[NSString alloc] initWithFormat:#"*** %# * \n\nGet the ***** App - It's Free!", entity.name];
UIImage *image = [[[UIImage alloc] initWithData:entity.image] autorelease];
SHKItem *item = [SHKItem image:image title:titleString];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet showFromBarButtonItem:barbtn animated:YES];
}
There is no method -[SHKItem image:url:title:]. So an error is being raised. Currently there is no mechanism to do what you require using ShareKit so you will have to customize ShareKit for your needs. You should also look at the Graph API.
Maybe what you want is a url item, with an image attached to it. If so, you can do this :
SHKItem *item = [SHKItem URL:[NSURL URLWithString:#"http://example.com/"] title:#"Check this link"];
[item setCustomValue:#"http://example.com/someimage.jpg" forKey:#"picture"];
[SHKFacebook shareItem:item];
I've implemented this with the latest sharekit, it works for me.
I am making an iphone game , In that I want to upload score on face book. I am new to face book codes, I've got it's API from github.com. But I don't know how to write or post directly my message on wall of face book of log in account else how to share my score on facebook. I've done log in portion.
Can any one help me????
Please refer the facebook api development at http://wiki.developers.facebook.com/index.php/Facebook_iPhone_SDK
Sample application also given by facebook for iPhone.
Thanks,
Jim.
Assuming the user has allready logged in and you have a vaild faceb0ok session, you could use something like this to get you started:
- (void) post {
postingDialog = [[[FBStreamDialog alloc] init] autorelease];
postingDialog.delegate = self;
postingDialog.userMessagePrompt = #"Prompt the User:";
NSString *name = #"Name of thing"
NSString *href = #"http://www.example.com"
NSString *caption = #"This is a caption"
NSString *description = #"This is a description";
NSString *imageSource = #"http://example.com/1.png";
NSString *imageHref = #"http://example.com/1.png";
NSString *linkTitle = #"Link title";
NSString *linkText = #"Text";
NSString *linkHref = #"http://www.example.com/iphone";
postingDialog.attachment = [NSString stringWithFormat:
#"{ \"name\":\"%#\","
"\"href\":\"%#\","
"\"caption\":\"%#\",\"description\":\"%#\","
"\"media\":[{\"type\":\"image\","
"\"src\":\"%#\","
"\"href\":\"%#\"}],"
"\"properties\":{\"%#\":{\"text\":\"%#\",\"href\":\"%#\"}}}", name, href, caption, description, imageSource, imageHref, linkTitle, linkText, linkHref];
[postingDialog show];
}