Mfmessagecomposeviewcontroller dismisses immediately after showing - objective-c

I've looked around all over the place, but I haven't found a solution to this oddly specific problem. I have a UIToolbar that contains, among other buttons, one that calls a method that shows an MFMessageComposeViewController. When it's called, if the person in the Contacts list hasn't been sent a message already, then everything goes fine and dandy. However, if the person has been sent a message already, then the view controller dismisses as soon as it opens, triggering MessageComposeResultCancelled, even though the user didn't get the chance to press the cancel button. Any ideas as to why this is happening?
For good measure, here is my message sending method:
-(void) showEmailComposer {
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
//[messageVC setMessageComposeDelegate:self];
messageVC.messageComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObject:#"NUMBER"];
[messageVC setRecipients:toRecipients];
NSString *smsString = [NSString stringWithFormat:#"Here's a link to my current location: http://maps.apple.com/?ll=%f,%f", _lat, _lon];
messageVC.body = smsString;
messageVC.messageComposeDelegate = self;
[self presentViewController:messageVC animated:YES completion:nil];
} else {
UIAlertView *alerty = [[UIAlertView alloc]
initWithTitle: #"Unable to send Message"
message: #"Sorry, but your device is incapable of sending messages right now."
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alerty show];
}
}

Related

Load a web view after opening a notification alert?

I made a RSS app, it works perfectly, I also added Push Notification Support, everything is good so far, am passing a title, alert, and a url as an extra field.
When my notification arrives, I show my alert, and you have 2 options "Thanx | Open"
All I want to do now is, when you click open from this alert, I need to redirect my user to a view that has a UIwebview and load the url I passed along with the notification.
Can anyone help me?
Here is my code:
// here is my app delegate
-(void)onReceivePushNotification:(NSDictionary *) pushDict andPayload:(NSDictionary *)payload {
[payload valueForKey:#"title"];
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"New Alert !" message:[pushDict valueForKey:#"alert"] delegate:self cancelButtonTitle:#"Thanks !" otherButtonTitles: #"Open",nil];
NSLog(#"message was : %#", [pushDict valueForKey:#"alert"]);
NSLog(#"url was : %#", [payload valueForKey:#"url"]);
[message show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Open"]) {
[[Pushbots getInstance] OpenedNotification];
// Decrease Badge count by 1
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber -1];
// Decrease badge count on the server
[[Pushbots getInstance] decreaseBadgeCountBy:#"1"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"updateRoot" object:nil];
} else {
// set Badge to 0
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
// reset badge on the server
[[Pushbots getInstance] resetBadgeCount];
}
}
My detail view is called : "APPDetailViewController", with a web view called "webView"
Please help me?
Thanks in advance.
You could create an instance of APPDetailViewController in your clickedButtonAtIndex method and present it. If you have tabs, you can switch to that tab, and then have a method to pass the url to so that it opens that page.

UIAlertView for user to download another app

I downloaded an app from app store and noticed that once I installed and opened the app, I got a UIAlertView suggesting that I download another app..
How can I achieve this? Are there any existing code that I can be directed towards?
Seems like a simple feature but I'd like to integrate it. Please see attachment
Here is my edited code, but the 'Hello' button won't link anywhere.. What am I doing wrong?
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Hello World!"
message:#"This is your first UIAlertview message."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"Hello", nil];
[message show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Hello"])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"https://itunes.apple.com/gb/app/islam/id667021108?mt=8&affId=1930871&ign-mpt=uo%3D4"]];
}
}
first you have to make alertView, if you want to show the alert as first thing but this code inside (ViewDidLoad) method
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"your title"
message:#"your message"
delegate:self
cancelButtonTitle:#"Not now"
otherButtonTitles:#"Download now"
, nil];
[alert show];
after viewDidLoad but this method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [alertView cancelButtonIndex]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"here but your application link"]];
}else{
}
}
//=================================================//
To know what's NSUserDefaults, I suggest to take a look the official doc.
And of course you can use it to fulfill your goal. You use a user default to store information about the current amount of runs in the app.
More or less like:
BOOL NotTheFirstTime = [[NSUserDefaults standardUserDefaults] boolForKey:#"NotTheFirstTime"];
if(!NotTheFirstTime){
// Show the alert view
// Then set the first run flag
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"NotTheFirstTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if that help you please make it the best question.
It is pretty simple:
1) Set up an UIAlertView as usual with the text and the button titles you like.
2) Set up the UIAlertView's delegate and use this method to figure out which button was clicked (whether the user does or does not want to go to the App Store):
alertView:clickedButtonAtIndex:
3) If the user wants to go to the App Store, open up an App Store link:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"<#This is your App Store Link#>"]];

error: address doesn't contain a section that points to a section in a object file

Hi i have searched here on the forum but no help found so i am posting it new. Here is the scenario, i am creating a mfmailcomposeviewcontroller in the main rootviewcontroller, i am displaying it by calling presentviewcontroller but when it is dismissed i get this error :
error: address doesn't contain a section that points to a section in a object file
The code i am using is given below:
-(void) mailButtonTapped
{
if ([MFMailComposeViewController canSendMail]) {
mailViewController_ = [[MFMailComposeViewController alloc] init];
mailViewController_.mailComposeDelegate = self;
[mailViewController_ setSubject:#"Try ..."];
[mailViewController_ setMessageBody:#"Hey I just tried ..." isHTML:NO];
NSData *videoData = [NSData dataWithContentsOfURL:movieURL_];
[mailViewController_ addAttachmentData:videoData mimeType:#"video/quicktime" fileName:#"Video.mov"];
[self presentViewController:mailViewController_ animated:YES completion:nil];
}
else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sharing Not Possible" message:#"Configure your mail to send the mail" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alertView show];
[alertView release];
}
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
NSString *title = #"Email";
NSString *msg = nil;
if (result == MFMailComposeResultFailed)
msg = #"Unable to send, check your email settings";
else if (result == MFMailComposeResultSent)
msg = #"Email Sent Successfully!";
else if (result == MFMailComposeResultCancelled || result == MFMailComposeResultSaved)
msg = #"Sending Cancelled";
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
[self dismissViewControllerAnimated:YES completion:nil];
}
After dismissing i receive the error:
error: address doesn't contain a section that points to a section in a object file
Please help me
I also had this error but with another scenario. I had a block property defined with #property (assign, nonatomic).
To fix this issue, I declared my block property with #property (copy, nonatomic).
Cheers
This error happens when an object / pointer is being accessed that doesn't exist anymore . And can also cause other bad access, 0x00000 value accessed etc.. errors.
So you are deleting/releasing a pointer , and then accessing later .
From looking at the code, and this is just a guess without debugging, you set the second AlertView's delegate to self, but then immediately dismiss the viewcontroller.
Try dismissing after the alert view is dismissed or the button is pressed, or maybe just setting the AlertView delegate to nil.
Even if that's not exactly the error, the main reason is somewhere you are releasing an object then trying to call a function or access it.
You can use it like this:
MFMailComposeViewController *mailViewController_ = [[MFMailComposeViewController alloc] init];
mailViewController_.mailComposeDelegate = self;
[mailViewController_ setSubject:#"Try ..."];
[mailViewController_ setMessageBody:#"Hey I just tried ..." isHTML:NO];
NSData *videoData = [NSData dataWithContentsOfURL:movieURL_];
[mailViewController_ addAttachmentData:videoData mimeType:#"video/quicktime" fileName:#"Video.mov"];
[self presentViewController:mailViewController_ animated:YES completion:nil];
[mailViewController_ release];
I also had this problem but caused by a very silly error, i wrote a property called frameon a class that inherits from UIView (it was a UITableViewCell but i think this would happen with every class that inherits from UIView) this overwrote the original frame property and caused this error.
Fixed just by changing property name.
The completion expects a block to be called when the animation of dismissal is completed.
Just remove "completion:nil" and it should work!
Regards.

UIAlertView with Button linking alternate ViewController

I needed a button that causes a UIAlertView with actions to pop up.
Once the Alert pops up it needs to have 1 button to cancel and stay on the same page and 1 button that links you to another ViewController.
This is what I pieced together from some forums but I have no idea what I'm doing and it gives me about 9 error messages. Please Help!
-(IBAction)Alert:(id)sender {
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:#"Alert"
message:#"Warning! By entering the Tutorial, all data will be lost. Are you sure you want to continue?"
delegate:self
cancelButtonTitle:#"Return to Data Collection"
otherButtonTitles:#"Continue", nil];
[Alert Show];
[Alert Release];
}
- (void)Alert:(UIAlertView *)Alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(Alert.tag==0) {
if(buttonIndex == 1)//OK button pressed
{
Tutorial *Info = [[Tutorial alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Info animated:YES];
}
The first box of code works so that when I press a button on my home screen an alert with 2 buttons pops up.
However, I can't get the second button to link me to the next ViewController.
Objective-C is case-sensitive.
[Alert show];
[Alert release];
and
- (void)alertView:(UIAlertView *)Alert clickedButtonAtIndex:(NSInteger)buttonIndex
(How do you think, it can work, if you rename the methods???)
remove if(Alert.tag==0) {
Why are you not passing a name for a nib-file here: Tutorial *Info = [[Tutorial alloc] initWithNibName:nil bundle:nil];
Please stick to coding conventions. objects are named in camelCase.
Conclusion
get you a good book or videos to learn from the beginning. Some resources to do so.

Trying to Integrate Mail Into my app, getting 2 warnings

I'm trying to integrate sending mail into my app, but I end up with 2 warnings. I am using Obj-C, the Cocos2d Framework. This is my code.
-(void) mailTapped: (id) sender {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:#"", nil]];
[composer setSubject:#"Check Out This Awesome App!"];
[composer setMessageBody:#"I found this great game on the App Store! It's called Mole Attack. It's a side scroller with an epic story. You can check out some screenshots of the gameplay and download it here. Download link - " isHTML:NO]; //Include link and pics
[self presentModalViewController:composer animated:YES]; // <--- warning - GameOver (name of class) may not respond to '-presentModalViewController:animated:'
}
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES]; // <--- warning - GameOver may not respond to '-dismissModalViewControllerAnimated:YES'
if (result == MFMailComposeResultFailed) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failed" message:#"The email was not sent. You must be in wifi or 3G range. Try again later." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Thanks in advance!
Are you sure your GameOver class is inheriting from UIViewController? That's the class that defines the two methods that you're getting warnings about.