iphone app exit with "No SIM card installed" - iphone

I use the MFMessageComposeViewController for sending in App sms. in iPhone 4.0, if there is no SIM card, the app exits. it just gives a pop up message "no sim card installed".
The delegate callback MessageComposeResultSent. But application exits. Is there any way to prevent it from exiting? or how to check if there is any SIM card in the phone?
Code snippets below:
/* Open the system sms service, copying the sms text in system clipboard. */
- (void) sendSMSAsURLRequest {
NSString *phoneNumber = friend.phoneMobile;
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
NSString *textUTIType = (NSString *)kUTTypeUTF8PlainText; // add MobileCoreServices.framework for this type.
[pasteBoard setValue:[self buildSMSText] forPasteboardType:textUTIType];
NSString *urlString = [NSString stringWithFormat:#"sms:%#", phoneNumber];
NSURL *url = [[NSURL alloc] initWithString: urlString];
[[UIApplication sharedApplication] openURL: url];
[url release];
}
-(void) sendInAppSMS {
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
controller.delegate = self;
if([MFMessageComposeViewController canSendText])
{
NSString *smsText = [self buildSMSText];
controller.body = smsText;
controller.recipients = [NSArray arrayWithObjects:friend.phoneMobile, nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(#"Cancelled");
break;
case MessageComposeResultFailed:{
NSString *alertString = NSLocalizedString(#"Unknown Error. Failed to send message", #"");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:alertString delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
break;
}
case MessageComposeResultSent:
NSLog(#"SMS sent");
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}

To Detect Sim Card is installed or not use following Code :
#import CoreTelephony;
CTTelephonyNetworkInfo *networkInfo = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
if (!carrier.isoCountryCode) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"No SIM Card Installed" message:nil delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else{
//Paste Your code here
}

The work around I am using now is, a flag in the app delegate,
- (void)applicationWillResignActive:(UIApplication *)aNotification {
if (shouldExitApp) {
exit(0);
}
}
In the SMS sending view controller,
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
((LuupAppDelegate *)[[UIApplication sharedApplication] delegate]).shouldExitApp = NO;
And set the flag again, when in the SMS sending view controller,
- (void) viewDidAppear:(BOOL)animated {
((LuupAppDelegate *)[[UIApplication sharedApplication] delegate]).shouldExitApp = YES;
[super viewDidAppear:animated];
}

Related

How to call Message App from My App? [duplicate]

This question already has answers here:
How to access and open the iPhone's SMS API from an iPhone app
(2 answers)
Closed 9 years ago.
How to call Message App from my current app.
I know to use this code...
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"sms:"]];
or
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:
#"sms:1-408-555-1212"]];
But what I want is just to call Message App, I don't want with phone no or without phone no.
Just want to open current Message App View.
Please help me....
MFMessageComposeViewController *messagComposer = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
messagComposer.messageComposeDelegate = self;
messagComposer.recipients = recipientsArray; // here give array of recipints
messagComposer.body = #"Some text";
[self presentModalViewController:picker animated:YES];
}
try like this for sending message
Try this ::
Import MessageUI framework in project.
in .h file,
#import <MessageUI/MessageUI.h>
Calling Method forSending SMS : [self SendSMS:#"YOUR_MESSAGE" recipientList:ARRAY_OF_RECIPIENTS];
Here, it you don't have any recipient, then pass array as nil.
Method ::
- (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];
}
[controller release];
}
Message Framework Methods ::
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Status:" message:#"" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil];
switch (result) {
case MessageComposeResultCancelled:
alert.message = #"Cancelled";
break;
case MessageComposeResultFailed:
alert.message = #"Failed";
break;
case MessageComposeResultSent:
alert.message = #"Send";
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
[alert show];
[alert release];
}
Hope, it'll help you.
Thanks.

Three else-if statements [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Hi I am trying to have 4 buttons and each of them have different alerts when pressed. I am running into an issue, I had 3 buttons and I decided to add a "Rate My App" Button but now it isnt' working, please help me. (By the way the error is Expexted Exspression)(Org.=Organization (Fixed in App), Email- Real email in app,
#define TAG_Band 1
#define TAG_DEV 2
#define TAG_EDEV 3
#define TAG_RATE 4
#interface Org.ContactInfo () <MFMailComposeViewControllerDelegate>
#end
#implementation Org.ContactInfo:UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Contacts";
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)ContactBand:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Contact the Band" message:#"Contact the Org. or go to their website!" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Visit the Org. Website",#"E-Mail The Org. President", #"E-Mail The Org. Treasurer", nil];
alert.tag = TAG_Band;
[alert show];
}
-(IBAction)ContactDev:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Contact Me" message:#"Contact Me on Features you would like me to consider! I will do my Best to look at all of the Suggestions!" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Visit My Website",#"E-Mail Me!", nil];
alert.tag = TAG_DEV;
[alert show];
}
-(IBAction)RateMyApp:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Rate My App" message:#"When Your Reviewing my App, Please remember that this app was at no cost to the Mighty Mustang Band." delegate:self cancelButtonTitle:#"Not Right Now" otherButtonTitles:#"Rate My App!!", nil];
alert.tag = TAG_RATE;
[alert show];
}
-(IBAction)AppInfo:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Version 1.0" message:#"More Updates Coming Soon. Please Feel Free to E-Mail me on features that you would like me to consider" delegate:self cancelButtonTitle:#"Not Right Now" otherButtonTitles:#"Email-Me", nil];
alert.tag = TAG_EDEV;
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag == TAG_Band){
if (buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://URL.org"]];
}
else if (buttonIndex==2){
//Subject
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"Org. President";
NSArray *toRecipients = [NSArray arrayWithObject:#"Person#Org.org"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
else if (buttonIndex==3){
//Subject
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"Org. Treasurer, ";
NSArray *toRecipients = [NSArray arrayWithObject:#"Person#Org.org"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
}
else if (alertView.tag == TAG_DEV){
if (buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://stepheniosdeveloper.wordpress.com"]];
}
else if (buttonIndex==2){
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"";
NSArray *toRecipients = [NSArray arrayWithObject:#"Email#gmail.com"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
}
else if (alertView.tag == TAG_EDEV);{
if (buttonIndex==1){
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"";
NSArray *toRecipients = [NSArray arrayWithObject:#"Email#gmail.com"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
}
else if (alertView.tag == TAG_RATE);{ //Expected Expression
if (buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://itunes.apple.com/us/app/Org/id607257427?ls=1&mt=8"]];
}
}
}
It worked Before I added the last on (TAG_RATE) but now I don't understand why it isn't working anymore. Please Help.
There is a typo in your code: you have extra ; after the last two else if conditions:
else if (alertView.tag == TAG_EDEV)/*;*/{ // extra `;`
//...
}
else if (alertView.tag == TAG_RATE)/*;*/{ // extra `;` //Expected Expression
// ...
}

Application crashing at Loading UIalertview indicator while loading data in iphone

I am calling URL on my Search button event to load data. I have put the code for Loading indicator Alert view by taking NSThread. I am using 3.2 xcode with 4.3 iOS. Every thing run smooth but on search button it shows Loading indicator and then crashing and showing following in console
Program received signal: “EXC_BAD_ACCESS”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.2 (8H7)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
Code under the Search Button click event:
- (IBAction) searchButton {
if([addressField.text length]==0)
{
UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:#"Alert" message:#"Please Tap on 'Show Me' & choose the 'Radius' first!!!" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil] autorelease];
[myAlert show];
}
else
{
[NSThread detachNewThreadSelector:#selector(updateFilterProgress) toTarget:self withObject:nil];
appDelegate = (MapTutorialAppDelegate *)[[UIApplication sharedApplication] delegate];
CLLocationCoordinate2D location;
float radius = [[arrayNo objectAtIndex:[pickerView selectedRowInComponent:0]] floatValue];
NSString *url = [NSString stringWithFormat:#"http://....url...../hespdirectory/phpsqlsearch_genxml.php?lat=%f&lng=%f&radius=%f",locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude,radius];
NSLog(#"%#", url);
NSURL *URL = [NSURL URLWithString:url];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
{
if([appDelegate.markers count] == 0){
UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:#"Alert" message:#"No results fond!!!" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil] autorelease];
[myAlert show];
}
else
{
resultButton.userInteractionEnabled = YES;
for (int i = 0; i < [appDelegate.markers count]; i++)
{
marker *aMarker = [appDelegate.markers objectAtIndex:i];
location.latitude = [aMarker.lat floatValue];
location.longitude =[aMarker.lng floatValue];
AddressAnnotation *annob = [[AddressAnnotation alloc] initWithCoordinate:location];
annob.title = aMarker.name;
annob.subTitle = aMarker.address;
[mapView addAnnotation:annob];
[annob release];
CLLocationCoordinate2D ausLoc = {location.latitude,location.longitude}; //for zoom in the showroom results region
MKCoordinateSpan ausSpan = MKCoordinateSpanMake(0.108889, 0.169922);
MKCoordinateRegion ausRegion = MKCoordinateRegionMake(ausLoc, ausSpan);
NSLog(#"No Errors");
mapView.region = ausRegion;
}
}
}
else
NSLog(#"Error Error Error!!!");
[addressField resignFirstResponder];
}
}
And for NSThread to Show Loaading indicator while loading data at the back.
- (void) updateFilterProgress{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
Reachability *r = [Reachability reachabilityWithHostName:#"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:#"No Internet Connection" message:#"This app require an internet connection via WiFi or cellular network to work." delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil] autorelease];
[myAlert show];
}
else{
UIAlertView *alertMe = [[[UIAlertView alloc] initWithTitle:#"Loading..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alertMe show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alertMe.bounds.size.width / 2, alertMe.bounds.size.height - 50);
[indicator startAnimating];
[alertMe addSubview:indicator];
[indicator release];
[alertMe release];
for (int i = 200; i > [appDelegate.markers count]; i--)
{
marker *aMarker = [appDelegate.markers objectAtIndex:i];
[alertMe dismissWithClickedButtonIndex:0 animated:YES];
}
}
[pool release]; }
Is there anything remaining in my code. Pleas correct me....
The variable alertMe is autoreleased and therefore you can't just send a release message to it. Remove the line [alertMe release]; and it will run perfectly.
You are probably accessing a released object. To see which one it is, set NSZombiesEnabled - this will show you which already released object you try to access, and you should be able to identify your problem.
Please have a look here to see how to enable the zombies in XCode 4:
http://42games.net/quick-note-on-setting-nszombieenabled-environment-variable-in-xcode-4/

mail application are not launching!

i am trying to implement the functionality of email in my application. i have added MessageUI-framework, along with header and MFMailComposeViewControllerDelegate protocol but i am facing problem. here is my code:
- (void)viewDidLoad {
[super viewDidLoad];
if(isViewPushed == NO) {
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
target:self action:#selector(email)] autorelease];
}
}
-(void) email
{
NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:#"<html><body>"] retain];
[emailBody appendString:#"<p>type text here</p>"];
UIImage *emailImage = [UIImage imageNamed:#"20-gear2.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
[emailBody appendString:[NSString stringWithFormat:#"<p><b><img src='data:image/png;base64.....,.......%#'></b></p>",imageData]];
[emailBody appendString:#"</body></html>"];
MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;
[emailDialog setSubject:#"My Inline Image Document"];
[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
if(! [MFMailComposeViewController canSendMail])
{
UIAlertView *cantMailAlert = [[UIAlertView alloc]
initWithTitle:#"cant email"
message:#"nt able to send email"
delegate:NULL
cancelButtonTitle:#"ok"
otherButtonTitles:NULL];
[cantMailAlert show];
[cantMailAlert release];
return;
}
MFMailComposeViewController *mailController = [[[MFMailComposeViewController alloc] init] autorelease];
[mailController setMessageBody:#"can send my mail" isHTML:NO];
mailController.mailComposeDelegate = self;
[self presentModalViewController:mailController animated:YES];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
if (error)
{
UIAlertView *cantMailAlert = [[UIAlertView alloc]
initWithTitle:#"mail error"
message: [error localizedDescription]
delegate:NULL
cancelButtonTitle:#"ok"
otherButtonTitles:NULL];
[cantMailAlert show];
[cantMailAlert release];
return;
}
NSString *resultString;
switch (result)
{
case MFMailComposeResultSent:
resultString = #"sent mail";
break;
case MFMailComposeResultSaved:
resultString = #"saved";
break;
case MFMailComposeResultCancelled:
resultString = #"cancel";
break;
case MFMailComposeResultFailed:
resultString = #"failed";
break;
}
if (resultString = #"saved")
{
NSString *msg = [NSString stringWithFormat:#"%# at %#\n", resultString, [NSDate date]];
UIAlertView *MailAlert = [[UIAlertView alloc]
initWithTitle:#"status"
message: msg
delegate:NULL
cancelButtonTitle:#"ok"
otherButtonTitles:NULL];
[MailAlert show];
[MailAlert release];
return;
}
[controller dismissModalViewControllerAnimated:YES];
[controller release];
//[self email];
}
but when i click on mail button then applictaion terminates and starts loading . it says can't able to store privious value!!
Why are you presenting two instances of MFMailcomposeviewcontroller in viewDidLoad? Why are you creating two objects namely emailDialog and mailController and presenting them?

How can I access iPod Library in my iPhone app

How access iPod Library in my iPhone app, like to the user listem music when is playing... like in the gameloft games, or the slide show from the Photos.app ?
Look at MPMusicPlayerController. I read it can access the iPod library. I never used it, and I don't know if it can help you...
- (void)addMusicBtnAction{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
mediaPicker.delegate = self;
//mediaPicker.prompt = #"Select Audio";
mediaPicker.prompt = NSLocalizedString (#"Select any song from the list", #"Prompt to user to choose some songs to play");
for (UIWindow* window in [UIApplication sharedApplication].windows) {
NSArray* subviews = window.subviews;
if ([subviews count] > 0)
for (UIAlertView *alrt in subviews) {
if ([alrt isKindOfClass:[UIAlertView class]]){
if (alrt.tag == 10020) {
[alrt dismissWithClickedButtonIndex:0 animated:YES];
}
}
}
}
[self presentModalViewController:mediaPicker animated:YES];
//[mediaPicker release];
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
NSArray * SelectedSong = [mediaItemCollection items];
if([SelectedSong count]>0){
MPMediaItem * SongItem = [SelectedSong objectAtIndex:0];
NSURL *SongURL = [SongItem valueForProperty: MPMediaItemPropertyAssetURL];
NSString *str = [NSString stringWithFormat:#"%#",SongURL];
appDelegate.musicFilePath = str;
//NSLog(#"Audio Loaded");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success!" message:#"Your audio has been selected" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil, nil];
alert.tag = 78787878;
[alert show];
// [alert release];
}
[self dismissModalViewControllerAnimated: YES];
}
// Responds to the user tapping done having chosen no music.
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker {
[self dismissModalViewControllerAnimated: YES];
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque animated:YES];
}