MFMailComposeViewController attachment choice - iphone

I'm using a MFMailComposeViewController in my iphone app and I'd like to give the user the choice to attach some pictures to the e-mail.
As there is no specific button by default, I was thinking about subclassing MFMailComposeViewController and adding a button for this. Unfortunately, according to the documentation the addAttachmentData: method shouldn't be called once the view has been displayed, so the choice can not be made during the mail composition.
I also thought about creating my own mail composer view, but according to this question: Send mail without MFMailComposeViewController , Apple does not want developers to do this as this could be used to abuse the user's mail account.
So, it seems the only solution is to ask the user prior to showing up MFMailCompose, and the only way for the user to change his choice would be to cancel mail composition and start it again, am I right?

When user tap the attach button, dismiss the MFMailComposeViewController and open the image picking controller. When the image is picked, create a new MFMailComposeViewController with the previous content and the new image as attachment.
I have not tried this. You can give a try.

Self answer: for me, the simplest way was to add a UIAlertView asking the user wether he wants to add the images or not, prior to showing up the mail composer view.
This is adequate as all images should be sent together (so it's all or none), but for more elaborate cases (chose some images from the iphone for example), Anil Sivadas' answer might be a solution.

Related

Retrieve the text entered by user in SLComposeViewController

I was wondering if theres a way to retrieve the complete text entered by the user in SLComposeViewController. I intend to fetch this value once SLComposeViewControllerCompletionHandler is returned to be True, and pass it as a parameter to Reply Twitter API.
Cheers!!
Officially, you can only "setInitialText:" and can not retrieve the text when the user is done entering it.
If the text were available as a property, then yes you could make use of it when the completion handler is called; but Apple has chosen not to make it available and therefore it's not currently possible through the official API's.
If this is something you need, I'd recommend filing a bug / enhancement request with Apple to ask them to consider it.
Now, all that said, I see that SLComposeViewController does inherit from UIViewController which means you can look at all the subviews of the view owned by the view controller. If you enumerate the subviews, look for the ones that are UITextViews or UITextField and there's where you should be able to find your text.

UIDataDetectorTypeAll and popup in app (or at least ask before switching)

Hey guys, I've recently implemented a UITextView into my app, and activated UIDataDetectorTypeAll. Everything works perfect, except when users click on the link, phone number, etc. it automatically kicks them out of my app and into the website, etc. Is there any way to have the website appear in my own app in a custom view, or at least have a popup that asks the user if they want to be taken to the website, call, etc?
Thank you!
Use a UIWebView and message it to load the URL. Wait, that's no help, sounds like you need to intercept the link so you can know the URL. The UITextView may be calling UIApplication's openURL function. This is ugly, but what if you replaced that openURL with your own using categories or subclassed UIApplication and added your own openURL function to override the one at the UIApplication level. Once there, you have a chance to intercept the call and direct it to your own UIWebView or at least pop up a UIAlertView.

How can i show Keyboard while open Mailcomposer?

I want to show keyboard when mail composer open without take any action.i mean when mail composer open automatically keyboard should display.
This isn't possible as far as I know. You might be able to traverse the views of the mailComposer to find the appropriate text field but that is a risky thing to do and liable to break.
Plus it might get your app rejected. Although it's not exactly clear. From the MFMailComposeViewController Class Reference:
Important: The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.

MFMailComposeViewController and cancelling "save" action sheet?

i am using MFMailComposeViewController inside my iphone app. I notice that if i enter any text in the body and then press the cancel button, i am prompted with an action sheet with an option to save/don't save the unsent message. I have two questions:
can I programmatically prevent the "save/don't save action sheet from appearing? MFMailComposeViewControllerDelegate doesn't appear to have anything along those lines
if i do save, where is the mail saved to? i looked in my mail accounts and didn't see anything saved in any of the "draft" folders.
No, you can't avoid the action sheet appearing. It's been added in iOS 4.x to, precisely, avoid tapping on the "Cancel" button inadvertently when writing a long email, which I think it's a good idea.
It is saved in "Drafts" folder of the account used to compose the e-mail (normally, your "default account" as it is registered in the Settings of your device). I've just tried using a couple of apps and it works.

Need new way to add a UITextField to a UIAlertView

So my app was rejected (it has been approved every other time i have put it in for review and I hadn't touched this code path in ages) or this line:
[myAlert addTextFieldWithValue:nil label:NSLocalizedString(#"Name",#"Name")];
Apparently addTextFieldWithValue:label:
is a private API...
so how are we supposed to put a UITextField inside an AlertView?
Can someone help?
Consider using a modal view controller, instead. No risk of app rejection.
You don't. Alert views are for displaying alerts only. Apple uses them to display text fields sometimes, but that's their prerogative (since they wrote the HI guidelines and all).
Find a different approach in your UI for prompting the user for data. This is a mobile platform, not a desktop. Using popups like this for information gathering on such a platform is usually inappropriate.