How to remove statusbar from messageviewcontroller? - iphone

I am sending sms programmatically from my view controller but now it is showing me statusbar and vertical black line
my code:
- (IBAction)SendTextBtnTapped:(id)sender {
[self sendSMS:#"Body of SMS..." recipientList:[NSArray arrayWithObjects: nil]];
}
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissModalViewControllerAnimated:YES];
if (result == MessageComposeResultCancelled)
NSLog(#"Message cancelled");
else if (result == MessageComposeResultSent)
NSLog(#"Message sent");
else
NSLog(#"Message failed");
}

just add this line
controller.wantsFullScreenLayout = YES;
OR add this line after present MessageViewController like bellow..
[self presentModalViewController:controller animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
OR for whole this viewController use bellow loginin viewWillAppear: paste this code..
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];

I think you can use wantsFullScreenLayout.
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
controller.wantsFullScreenLayout = YES; //<== add this
[self presentModalViewController:controller animated:YES];
}

Related

MFMailComposeViewController not dismiss

I used MFMailComposeViewController for sending mail to others. When click a button the compose sheet is opening, and i can able to type To address,subject,message body. But after clicking send button the mail page is not closing.
code:
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#"My image"];
UIImage *myImage = [UIImage imageNamed:#"mobiletuts-logo.png"];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailer addAttachmentData:imageData mimeType:#"image/png" fileName:#"Image"];
NSString *emailBody = #"Hi, my image";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];
}
- (void)mailComposeController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MFMailComposeResultCancelled:
break;
case MFMailComposeResultSent:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
Sorry. Forget to add these lines. After this lines mail working
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissViewControllerAnimated:YES completion:nil];
}
Try this
[self presentModalViewController:mailer animated:YES];
for dismiss
[self dismissModalViewControllerAnimated:YES];

use FacebookComposeViewController ,but photo can't show

I learned this Sample code, and try to implement in my app, but the photo can't show.
enter link description here
- (IBAction)facebookBtn_down:(id)sender {
if (osVer >= 6.0) {
SLComposeViewController *fbVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbVC setInitialText:apple_F_MSG];
[fbVC addURL:[NSURL URLWithString:APP_URL]];
[fbVC setCompletionHandler:^(SLComposeViewControllerResult res) {
if (res == SLComposeViewControllerResultDone) [self AlertToukou];
}];
[self presentModalViewController:fbVC animated:YES];
} else {
DEFacebookComposeViewController *fbVC = [[[DEFacebookComposeViewController alloc] init] autorelease];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[fbVC setInitialText:apple_F_MSG];
[fbVC addURL:[NSURL URLWithString:APP_URL]];
[fbVC setCompletionHandler:^(DEFacebookComposeViewControllerResult res) {
if (res == DEFacebookComposeViewControllerResultDone) [self AlertToukou];
[self dismissModalViewControllerAnimated:YES];
self.modalPresentationStyle = UIModalPresentationFullScreen;
}];
[self presentModalViewController:fbVC animated:YES];
}
}
please give me some advice,thank you!
From the documentation page of that it says,
DEFacebookComposeViewController *facebookViewComposer = [[DEFacebookComposeViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[facebookViewComposer setInitialText:#"Look on this"];
[facebookViewComposer addImage:[UIImage imageNamed:#"1.jpg"]];//<------Check This
facebookViewComposer.completionHandler = completionHandler;
[self presentViewController:facebookViewComposer animated:YES completion:^{ }];
You should use addImage function and give proper UIImage object than it should be working.
I found the problem:
I did not set the Key "forKey:#"source",than can't post on the wall
errorError Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)"
if ([self.images count] > 0) {
[d setObject:UIImagePNGRepresentation([self.images lastObject]) forKey:#""];
graphPath = #"me/photos";
}

game center unavailable player is not signed in

On iOS 6 when a player is not signed in and is trying to use GameCenter an UIAlertView with the text that i put in title pops up. "game center unavailable player is not signed in". My question is is it possible to replace that UIAlertView with anything else, with my own interface element?
[GKLocalPlayer localPlayer].authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
if ([[GKLocalPlayer localPlayer] isAuthenticated])
{
NSLog(#"[gamecenter] player authenticated: %#\n", [GKLocalPlayer localPlayer]);
[self gamecenterLoadAchievements];
[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite)
{
// Insert application-specific code here to clean up any games in progress.
if (acceptedInvite)
{
NSLog(#"Accepted invitation");
isInvited = YES;
[[GameLevel sharedGameLevel] setCurrentGameMode:GameModeGameCenter];
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite] autorelease];
mmvc.matchmakerDelegate = self;
AppDelegate * delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
[delegate.viewController presentModalViewController:mmvc animated:YES];
}
else if (playersToInvite)
{
NSLog(#"Players to invite");
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = playersToInvite;
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentModalViewController:mmvc animated:YES];
}
};
}
else
if (viewController)
{
AppDelegate *delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
NavigationController *_viewController = delegate.viewController.navController;
[_viewController presentViewController: viewController animated: YES completion:nil];
}
else
{
NSLog(#"[gamecenter] %#\n", error);
gcLoginFailed = YES;
if ([[error domain] isEqualToString:GKErrorDomain])
{
if ([error code] == GKErrorNotSupported)
gcIsSupported = NO;
else
if ([error code] == GKErrorCancelled)
gcLoginCancelled = YES;
}
}
};
Just not use UIAlertView Use your own graphics with a UIButton
If you are using the disableGameCenter method in authenticating , just don't use it , instead of it use a integer ilk int isPlayerSignedIn . And just return it to 1 or 0 . So ;
if (isPlayerSignedIn==0) {
//display your graphics
}
else do nothing .
edit :
else
if (viewController)
{
AppDelegate *delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
NavigationController *_viewController = delegate.viewController.navController;
[_viewController presentViewController: viewController animated: YES completion:nil];
}
just if you don't use these lines of code you will see that you don't get that UIAlertView
Then you can implement a "game center is unavailable" staff , but additionally you have to implement a login screen too.

MFMessageComposeViewController dismiss keyboard

i'm having troubles with my MFMessageComposeViewController. I would like to use SMS in-app.
Everything work fine for sending SMS, so far so good. But when i hit the cancel button (or send button too) top of my view disapeared but the keyboard did not. It's maybe because i don't use modale view, but only a addSubview.
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
if (result == MessageComposeResultCancelled)
{
NSLog(#"Message annulé");
[controller resignFirstResponder];
[controller.view removeFromSuperview];
[controller release];
}
else if (result == MessageComposeResultSent)
{
NSLog(#"Message envoyé");
...
}
else
{
NSLog(#"Message non envoyé");
...
}
}
-(void)sendSMS:(NSString *)bodyOfMessage :(Phone *)recipient
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
NSMutableArray *toRecipients = [[NSMutableArray alloc]init];
[toRecipients addObject:recipients.phoneNumber];
[picker setRecipients:(NSArray *)toRecipients];
[toRecipients release];
NSString *bodyString = nil;
bodyString = bodyOfMessage;
[picker setBody:bodyString];
[self addSubView:picker.view];
[picker release];
}
}
Any idea ? Had I to use only modalView ?
sorry for spelling mistake...
Thank you. Tommy
Yes, you have to use the modalviewcontroller.
[self presentModalViewController:picker];
Also, you're creating two instances of the MFMessageComposeViewController, first for checking if it can send text and then another to actually show it. I advise to create just one, it's better for the memory :) also the first one is leaking since you didn't release it. Good luck!
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
NSString *bodyString = nil;
NSMutableArray *toRecipients = [[NSMutableArray alloc]init];
[toRecipients addObject:#"phone here"];
[picker setRecipients:(NSArray *)toRecipients];
[toRecipients release];
bodyString = [NSString stringWithFormat: #"Message body"];
[picker setBody:bodyString];
[self presentModalViewController:picker animated:YES];
[picker release];
}
Try close existing keyboard, before presenting modal view controller with MFMessageComposeViewController:
[self.view endEditing:YES]; //close keyboard if it opened
[self presentModalViewController:messageController animated:YES];

How to send mail from iphone app?

I am try to send mail from my app. I want to type(dynamically) recipient id,ccid,sub and message.
Thanks
Senthilkumar
on iOS 3+
Import #import in your view controller header.
Then:
-(void)showMailPanel {
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
// only on iOS < 3
//if ([MFMailComposeViewController canSendMail] == NO)
// [self launchMailApp]; // you need to
mailComposeViewController.mailComposeDelegate = self;
[mailComposeViewController setToRecipients:[NSArray arrayWithObjects:#"email address1",#"email address 2",nil]];
[mailComposeViewController setSubject:#"your subject"];
[mailComposeViewController setMessageBody:#"your body" isHTML:YES];
mailComposeViewController.delegate = self;
[self.navigationController presentModalViewController:mailComposeViewController animated:YES];
[mailComposeViewController release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(#"Result: canceled");
break;
case MFMailComposeResultSaved:
NSLog(#"Result: saved");
break;
case MFMailComposeResultSent:
NSLog(#"Result: sent");
break;
case MFMailComposeResultFailed:
NSLog(#"Result: failed");
break;
default:
NSLog(#"Result: not sent");
break;
}
[controller dismissModalViewControllerAnimated:YES];
}
-(void)launchMailApp {
{
NSString *recipients = #"dest_email";
NSString *email = [NSString stringWithFormat:#"%#%#", recipients, subject];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
You need things like this:
//Import this in your .h file
#import <MessageUI/MessageUI.h>
...
MFMailComposeViewController *mailController = [[[MFMailComposeViewController alloc] init] autorelease];
mailController.mailComposeDelegate = self;
[mailController setSubject:[NSString stringWithFormat:#"Report a problem - #%#", yourUserID]];
[mailController setToRecipients:[NSArray arrayWithObject:#"support#yourWebsite.com"]];
[self presentModalViewController:mailController animated:YES];
Besides, the parent view controller (the delegate) needs to conform to the MFMailComposeViewControllerDelegate protocol:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
//Extra implementation here...
[self dismissModalViewControllerAnimated:YES];
}