As you can see in this , the keyboard is going up too high when I touch the textarea. Any idea on what's causing this particular problem. How can I make the keyboard stick to the bottom of screen ?
[UPDATE] (code):
#import "ViewController.h"
#import <MessageUI/MessageUI.h>
#interface SettingsViewController () <MFMailComposeViewControllerDelegate>
#end
#implementation ViewController
- (IBAction)feedBack:(id)sender {
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion];
NSString *model = [[UIDevice currentDevice] model];
NSString *version = #"1.0";
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setToRecipients:[NSArray arrayWithObjects: #"feedback#example.com",nil]];
[mailComposer setSubject:[NSString stringWithFormat: #"Feedback about App V%#",version]];
NSString *supportText = [NSString stringWithFormat:#"Device: %#\niOS Version:%#\n\n",model,iOSVersion];
supportText = [supportText stringByAppendingString: #"Please write your feedback or suggestions"];
[mailComposer setMessageBody:supportText isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult: (MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
That has nothing to do with your code. The user can move the keyboard from the bottom of the screen or split it. You have done exactly that as the user. You, as the user, need to drag the keyboard down again if that's what you want.
And you don't do anything about it, because it is behaviour that the user intentionally chose. For people who write code that keeps track of the keyboard appearing / disappearing and moving items out of the area covered by the keyboard: If the keyboard is undocked or split, or if the user uses a hardware keyboard, you will get no notifications about the area covered by the keyboard.
Related
I created an app based on the "Tabster" sample code from Apple. The app runs great, but I want to add email to it. I created an email app. and have tried every approach I can think of, learn from a tutorial, or read, but it continually crashes. I posed the question on the Apple Dev. forum and several responses were to simply "copy the files over to the existing app. and you should be good." Obviously its not this simple. I have added the MessageUI Framework and have tried copying the files in many different ways and Im am still stuck. Its Friday and this one problem has held me up since Monday. I guess the first part is the fact that there are 2 main.m files and I have tried combining them, I have tried renaming the mail's main.m file to emailmain.m. I dont know what else to try.
Its amazing to me that all of the documentation and all of the tutorials out there about creating email within an iOS app all start off with creating a new application. What am I missing? How do I add email into a fully functioning app. I would appreciate any guidance, links to literature, or tutorials on the subject.
Any help I can get on this will be tremendously appreciated. There are several other types of things I would like to add on to it, but I cant even get email implemented into it!
Thank you for help you can provide.
John
This is the method I use all the time. It should be able to be added to ANY UIViewController simple and cleanly.
Import your framework:
#import <MessageUI/MessageUI.h>
Make sure you include your delegate in the interface:
#interface MyViewController : UIViewController <MFMailComposeViewControllerDelegate>
Then in your implementation add this method or a variation if you need it to be an IBAction or something like that:
- (void)sendEmail
{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
[email setSubject:#"My Email Subject"];
[email setMessageBody:#"My message body." isHTML:NO];
[self presentModalViewController:email animated:YES];
} else {
UIAlertView *emailAlert = [[UIAlertView alloc] initWithTitle:#"Email Failure" message:#"Your device is not configured to send email" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[emailAlert show];
}
}
You can call this method on button click or anything you want. It will pull up an email composer view where your user can hit send.
You need to import the MessageUI Framework. Where ever you want to use it import it in the corresponding .h file and set up the MFMailComposeViewControllerDelegate.
#import <MessageUI/MessageUI.h>
#interface ViewController : UIViewController <MFMailComposeViewControllerDelegate>
Then when you want to send a message use the following code in the .m file:
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
// Optional Configuration Parameters to make life easier for the user
[mailViewController setSubject:subjectString];
[mailViewController setMessageBody:messageString isHTML:YES];
[mailViewController setToRecipients:recipientsArray];
// Present the VIew Controller and clean up after ourselves
[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
Add the appropriate delegate method, you can use it to dismiss the controller once the email is sent:
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}
Here Is asample code to create email with an image as attachment .you can modify it according to your needs.
-(void)createEmail
{
NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:#"<html><body>"] retain];
[emailBody appendString:#"<p>Some email body text can go here</p>"];
UIImage *emailImage = [UIImage imageNamed:#"myImageName.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
NSString *base64String = [imageData base64EncodedString];
[emailBody appendString:[NSString stringWithFormat:#"<p><b><img src='data:image/png;base64,%#'></b></p>",base64String]];
[emailBody appendString:#"</body></html>"];
NSLog(#"%#",emailBody);
//mail composer window
MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;
[emailDialog setSubject:#"My Inline Image Document"];
[emailDialog setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
[emailBody release];
}
I would like to add to my application a "Tell Friend" option which allow user to select multiple contacts to send them email. Contact need to be filtered to the one who have email address only.
does any one know such ready example that I could reuse.
I recently searching for the same problem and I found iTellAfriend. It works for me.
Download this source code from github/iTellafriend. Open zip file and inside src file drag iTellAFriend.h and iTellAFriend.m to your project. Check "Copy items into destination group folder(if needed)" and "Create group folder for any added folders"
In your appdelegate.m add #import "iTellAFriend.h"
Add following to your appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//[iTellAFriend sharedInstance].appStoreID = yourAppId;
[iTellAFriend sharedInstance].appStoreID = 408981381; //example
return YES;
}
Add #import "iTellAFriend.h" to your ViewController.m and anywhere in your ViewController.m call following method (preferably in a button)
if ([[iTellAFriend sharedInstance] canTellAFriend]) {
UINavigationController* tellAFriendController = [[iTellAFriend sharedInstance] tellAFriendController];
[self presentModalViewController:tellAFriendController animated:YES];
}
In iTellAFriend.m modify following
- (UINavigationController *)tellAFriendController
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:self.messageTitle];
[picker setMessageBody:[self messageBody] isHTML:YES];
return picker;
}
to
- (UINavigationController *)tellAFriendController
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObjects:#"xxxx#xxxx.com", #"xxxxx#xxxx.com", nil];
[picker setToRecipients:toRecipients];
[picker setSubject:self.messageTitle];
[picker setMessageBody:[self messageBody] isHTML:YES];
return picker;
}
when you click your button following scene will appear it wont send the email on simulator but on device
I´m trying to integrate ShareKit in my ios game.
Everything is working fine and the actionsheet is shown and I can interact with it but I´m not able to return the focus to my app when the sharekit action has finished (by closing the actionsheet or finishing any action).
I have tried in several ways but any has worked for me. What´s happening?
I´m not an expert programmer so I expect I´m missing something.
I´m
This is my .h
#import <UIKit/UIKit.h>
#import "SHK.h"
#import "SHKConfiguration.h"
#interface SocialWrapper: UIViewController{
}
- (id) init;
- (void) open;
- (void) dealloc;
#end
and .m
#import "SocializeWrapper.h"
#implementation SocialWrapper
- (id) init {
self=[super init];
DefaultSHKConfigurator *configurator = [[DefaultSHKConfigurator alloc] init];
[SHKConfiguration sharedInstanceWithConfigurator:configurator];
[SHK flushOfflineQueue];
return self;
}
- (void) open
{
NSString *someText = #"Hello Earth!";
SHKItem *item = [SHKItem text:someText];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[window addSubview:self.view];
[SHK setRootViewController:self];
[actionSheet showInView:self.view];
}
- (void) dealloc {
NSLog(#"SHK dealloc");
[self release];
[super dealloc];
}
#end
I´m calling it by using this wrapper
#import "SocializeWrapper.h"
SocialWrapper *socialize;
void SHKinit(void) {
NSLog(#"SHK Init");
socialize = [[SocialWrapper alloc] init];
}
void SHKopenWeb(void){
NSLog(#"SHK Open actionsheet");
[socialize open];
}
I´m working with ios 5, xcode 4.3.2 and the last sharekit version from the git.
I think I have to dissmiss my SocialWrapper once the actionsheet is closed but I don´t know how to capture that event, or even if this is correct. I´m stucked.
any help will be greatly appreciated.
UPDATE
As comment adviced, now the controller is on a category, using the actionsheet delegate, the focus can be regained when clicking the cancel´s actionsheet button. The problem still persists when an action is finished or cancelled. Don´t know how to capture that event.
This is my category code:
#import "SocialWrapper.h"
#implementation UIViewController (SocialController)
-(void) loadconfig
{
DefaultSHKConfigurator *configurator = [[DefaultSHKConfigurator alloc] init];
[SHKConfiguration sharedInstanceWithConfigurator:configurator];
[SHK flushOfflineQueue];
}
- (void) open
{
NSLog(#"Opening social button");
NSString *someText = #"Monkey Armada rules!";
SHKItem *item = [SHKItem text:someText];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[window addSubview:self.view];
[actionSheet setDelegate:self];
[SHK setRootViewController:self];
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(#"SHK actionsheet dissmiss with button %d", buttonIndex);
if(buttonIndex == 4)
{
NSLog(#"SHK close actionsheet");
[self dismissViewControllerAnimated:YES completion:nil];
[self.view removeFromSuperview];
}
}
#end
Well since SHKActionSheet is a subclass of UIActionSheet you can set the delegate of that class to self to know when the dismissal happens.
Also, [self release]; in dealloc is complete misunderstanding of what release does, if you're in dealloc then releasing self won't do anything !
Learn the memory management rules.
I should also warn you that [window addSubview:self.view] is deprecated, you should not do that at all. In fact, I don't see a reason to wrap share kit stuff each view controller should be able to write that code easily. At worse you could put that code in a category on UIViewController if you don't want to rewrite the code every time.
I am using MFMailComposeViewController in my app and the mail sending part seems to be OK.
But when I leave the mail app, things go wrong :
- one toolbar (UIToolbar object) has disappeared.
- one pointer (UIImageView*) has become nil, without me doing anything for that to happen.
In other words the calling environment is changed although I do not want it to change.
Where could be my mistake?
Here is my code, in case someone can see something wrong :
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
[controller dismissModalViewControllerAnimated:YES];
}
-(IBAction)sendAsEMail {
MFMailComposeViewController *mailComposeViewController=[[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate=self;
[mailComposeViewController setSubject:#"Mail subject"];
[mailComposeViewController setMessageBody:#"This is for you !" isHTML:NO];
[mailComposeViewController addAttachmentData:
[NSData dataWithContentsOfFile:[[My_ViewController getDocDir] stringByAppendingPathComponent:
[pictureNames objectAtIndex:userItemSelected]]]
mimeType:#"image/png" fileName:#"Picture.png"];
if (mailComposeViewController) [self presentModalViewController:mailComposeViewController animated:YES];
[mailComposeViewController release];
}
Thanks for any piece of relevant information.
Try out this link it explain in detail
Add framework
Then .h file header files
Then .m file the mail code
Check at this link.
I have a webview object (aWebView) which was added on top of current window like this -
UIWindow *webWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 20, 320,460)];
[webWindow addSubview:aWebView];
[webWindow makeKeyAndVisible];
I have a ViewController (viewcontrollerobj) which is subView of aWebView -
[webView addSubview:viewcontrollerobj.view];
Then I am calling sendInAppMail method in the ViewController-
[sviewcontroller sendInAppMail];
SendInAppMail looks like this -
MFMailComposeViewController *mailController = [[[MFMailComposeViewController alloc] init] autorelease];
if([MFMailComposeViewController canSendMail])
{
[mailController setMessageBody:#"hello" isHTML:NO];
[mailController setSubject:#"subject"];
mailController.mailComposeDelegate = self;
[self presentModalViewController:mailController animated:YES];
[mailController release];
}
didFinishWithResult looks like this -
- (void)mailComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MFMailComposeResultCancelled:
break;
case MFMailComposeResultSent:
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
Mail viewcontroller shows up fine. The problem is that when I hit cancel it shows the delete/save draf t option and after clicking either delete/save the mail viewcontroller doesn't go away!
When I look at console it shows this log message -
"Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:]."
I am not using UIActionSheet anywhere and haven't used in the past so I am not able to understand what it is saying.
I looked at this - https://stackoverflow.com/a/6015957/516938
But it seems like the solution given is very specific to a situation.
Not sure this is the issue, but this is the first thing I would look at.
Based on the error message that you got it sounds like either one of the views (the aWebView or the one from viewcontrollerobj that you defined) doesn't allow enough space for the MFMailComposeViewController, meaning that the dimensions of it are smaller than the MFMailComposeViewController requires. It isn't actually clipping the content, so you see it, but it is blocking the touches so that they don't get to the MFMailComposeViewController.
I hope that is clear enough - I had a hard time describing my thoughts here correctly.