Application crashes when asking if user wants to use Location Services - iphone

I have an iPhone app that is using CoreLocation.
Upon first installing the app, the iPhone system message is displayed asking whether or not the user wants to allow location services, if they click yes, my app suddenly displays the first screen of my app (I'm using a navigation controller), and crashes. This is what I see in the log -
warning: UUID mismatch detected with the loaded library - on disk is:
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony
=uuid-mismatch-with-loaded-file,file="/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony"
Program received signal: “EXC_BAD_ACCESS”.
And the stack trace looks like this
My code isn't too far off from the LocateMe sample (which works on my device). I have this:
CLLocationManager *clLocationManager = [[CLLocationManager alloc] init];
clLocationManager.delegate = self;
if (clLocationManager.locationServicesEnabled) {
[clLocationManager startUpdatingLocation];
} else {
self.searchBar.placeholder = #"Enter location";
}
Any idea on waht I'm doing wrong?

does your navigation controller support CLLocationManagerDelegate? it looks like it's crashing trying to send you an event.
what does your locationManager:didUpdateToLocation:fromLocation: function look like?

It looks like this is a byproduct of this question
To solve the problem, I wound up following this approach
Basically, in my ViewController's dealloc method -
- (void)dealloc {
locationManager.delegate = nil;
[locationManager release];
}

Related

How to handle a system alert message for iOS?

I have an app where i am using UIImagePickerController to use the native camer inorder to click pictures but the when the photo gallery on the device is full. I get a alert message which says "Cannot Take Photo - There is not enough available storage to take a photo.You can manage your storage in Settings". I am given two options to click the "Done" button or "Settings" button. Clicking either of them does nothing and the app freezes completely.
This is what i get from the console logs
Not enough space to take a picture. Available space is 0
The code for the picker
UIImagePickerController *mediaPicker = [[UIImagePickerController alloc] init];
mediaPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
mediaPicker.delegate=self;
mediaPicker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:mediaPicker animated:YES];
I have implemented and tried all the delegates already and its not calling any delegate.
Is there any way i can implement something where i can use a listener to detect when this error occurs and take back the user to the previous screen ?
Sounds like your device run out of memory, system sent lots of "Out of Memory" notifications and your app got one, too. As result your app released the UIViewController, which originally launched UIImagePickerController.
Now when you dismiss imagePicker with Done/Settings button, control returns back to your app. The old UIViewController doesn't exist any more and you haven't implemented code to recreate it from scratch in this kind of situations. The device looks like it frozen, but only because UI wasn't redrawn by your app. Otherwise app works just fine.
You can check this case by implementing didReceiveMemoryWarning method into every UIViewController and logging, if it's called:
- (void)didReceiveMemoryWarning
{
NSLog(#"%#", [self description]);
[super didReceiveMemoryWarning];
}
One of my favourite bugs. Easy to miss :)
This sounds like a bug in iOS.
You should file a feedback at https://feedbackassistant.apple.com/.

Puzzling Error on Iphone AddSubView function

if(popup != nil) {
[popup.view removeFromSuperview];
[popup release];
}
popup = [[OfferPopup alloc] initWithNibName:#"OfferPopup" bundle:nil];
popup.offer = offer1;
popup.delegate = self;
[self.view addSubview:popup.view];
1)The App crashed when trying to do the addSubView popup.view
2)I stepped through the code and checked offer1 is valid, popup is valid has a memory address. popup is a view controller.
3)The current module is a viewcontroller too.
4)The App crashed due EXEC_BAD_ACCESS.
5)I used performance tool and enabled Zombie checking, and ran it, again the app crashed without the performance tool indicate where the reference count goes wrong.
I am puzzled as how to troubleshoot.
Check if Popup xib file exists, or see if you are naming it right in your initialisation code. See if the viewController class is correctly assigned in File Owner in IB.

monitoredRegions empty even though startMonitoringForRegion:desiredAccuracy: is called

I am developing a iPhone app running on iOS5, and am unable to set up geofences when I call the startMonitoringForRegion:desiredAccuracy: method on click of a button.
It works fine in the simulator when I print out the regions in monitoredRegions, but when running on an actual iPhone 4, the monitoredRegions is always empty. Expectedly, the didEnterRegion: and didExitRegion: methods are not called as well.
Another puzzling fact is that on BOTH the simulator and the iPhone 4 device, the CLLocationManagerDelegate method didStartMonitoringForRegion: is never called as well.
Would appreciate some help here, thank you!
EDIT:
this is method that I call on click of a button:
-(void) queueGeofence: (CLLocationCoordinate2D)selectedBranch userCoordinate:(CLLocationCoordinate2D)userCoordinate radius: (CLLocationDegrees)radius {
geofence = [[CLRegion alloc] initCircularRegionWithCenter:selectedBranch radius:radius identifier:#"geofence"];
CLLocationAccuracy acc = kCLLocationAccuracyNearestTenMeters;
[locationManager startMonitoringForRegion:geofence desiredAccuracy:acc];
[CLLocationManager regionMonitoringEnabled];
NSLog([CLLocationManager regionMonitoringEnabled] ? #"regionMonitoringEnabled:Yes" : #"regionMonitoringEnabled:No");
NSLog([CLLocationManager regionMonitoringAvailable] ? #"regionMonitoringAvailable:Yes" : #"regionMonitoringAvailable:No");
NSLog(#"LOCATIONMANAGER monitored regions: %#", [locationManager monitoredRegions]});
}
Region monitoring is both enabled and available, but monitoredRegions is still giving me back nothing.
If you look in CLLocationManager.h, the comments in the header for startMonitoringForRegion:desiredAccuracy: state that
If a region with the same identifier is already being monitored for this application, it
will be removed from monitoring. This is done asynchronously and may not be immediately reflected in monitoredRegions.
Therefore, you shouldn't necessarily expect that [locationManager monitoredRegions] would include your newly added region since it is added asynchronously.
Are you implementing the delegate method for locationManager:monitoringDidFailForRegion:withError:? Maybe that's getting called instead of locationManager:didStartMonitoringForRegion:. Also note that a region with the same identifier as an existing region will get removed, so you might be running into some unexpected problems because you're reusing "geofence" as your identifier.
First of all, you should be sure, that your app has a permission to use LocationManager. Check it when you alloc your manager.
[CLLocationManager authorizationStatus];
I had the same trouble when start app and decline a permission. And after deleting and rebuilding app. I had a flag, that user didn't accept it. Turn it on.
If you are just going by your NSLog, it probably isn't going to work. [locationManager monitoredRegions] returns an NSSet of CLRegions. They won't display to your log that way. Try this:
NSSet *setOfRegions = [locationManager monitoredRegions];
for (CLRegion *region in setOfRegions) {
NSLog (#"region info: %#", region);
}

iPhone application crash (iOS4 Only)

My iPhone application occasionally crashs the first time it is run after being installed. After this every time i try and run the app it remains on the splash screen or even a black screen until eventually it dies. I have to restart the device to get the application to work. After this it works fine every time. The only change between the OS3 code and 4 is the property 'UIApplicationExitsOnSuspend' to force the app to reload every time instead of suspending. Any help would be great.
Here are the two Code snippets:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
taskListViewController = [[TaskListViewController alloc] initWithNibName:#"TaskListView" bundle:nil];
taskListViewController.managedObjectContext = self.managedObjectContext;
[taskListViewController setAppDefaults];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:taskListViewController];
[taskListViewController release];
navController.navigationBar.tintColor = [UIColor blackColor];
[window addSubview:[navController view]];
[window makeKeyAndVisible];
}
- (void)viewDidLoad
{
NSLog(#"viewDidLoad - Start");
[super viewDidLoad];
NSError *error = nil;
if(![[self fetchedResultsController] performFetch:&error])
{
NSLog(#"Error with initial fetch %#, %#", error, [error userInfo]);
}
[activityIndicator startAnimating];
self.navigationItem.leftBarButtonItem.enabled = NO;
self.navigationItem.rightBarButtonItem.enabled = NO;
infoButton.enabled = NO;
syncButton.enabled = NO;
taskListTable.userInteractionEnabled = NO;
taskListTable.allowsSelection = NO;
checkingRecovery = true;
[self insertCheck];
}
Other Methods mentioned above:
[taskListViewController setAppDefaults]
[self insertCheck];
setAppDefaults - Enumerates through the settings bundle applying the defaultValues to NSUserDefaults if they have not been set already by the user in peferences.
insertCheck - Performs some queries on the db to ensure file integrity on audio recordings but in this case as this is the first time the app is loaded it will do nothing.
Update:
I have commented out the extra method calls (the two above) and i am still having the problem.
I have found a few people having the same sort of problem on the apple developer forum with no solutions. One reply was from a user having the same problem but there application did get approved on the app store.
Thanks Sj
If you are debugging the application when it crashes, you should get a stack trace, which will show you on what line the application crashes.
If you could provide the stack trace it would be much easier to find the cause of the crash.
Have you looked at the log files?
You can copy them off your iPhone if you plug it in, load organizer (Windows->Organizer in XCode) and select device logs.
If you see a log for the time your application crashed, it should include the call stack (which should include the function causing it to crash)
Alternatively it could be that you're stuck in some code run at startup - and if your application doesn't start in a timely manor (within 30 seconds IIRC) iOS kills it.
Try it without the managedObjectContext piece and see if you are still crashing. What does the log say when you crash? Do you get a memory exception?

iPhone locationManager:didFailWithError problem when GPS disabled

So, I've followed other related threads, but for some reason I'm still having this error and I'm about ready to tear my hair out. I have implemented locationManager:didFailWithError to check and see if a user selects 'Don't Allow' to use the current location.
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(#"IN ERROR");
if ([error code] == kCLErrorDenied){
[manager stopUpdatingLocation];
}
}
However, the following error always appears when the user selects 'Don't Allow'...it's strange, especially the order that the text 'IN ERROR' appears.
ERROR,Time,293420691.000,Function,"void
CLClientHandleDaemonDataRegistration(__CLClient*,
const
CLDaemonCommToClientRegistration*,
const __CFDictionary*)",server did not
accept client registration 1
2010-04-19 21:44:51.000
testApp[1414:207] IN ERROR
So, it's outputting this error even before it has a chance to get into the didFailWithError function. Does anyone have any ideas of what might be happening? The rest of the locationManager code is as follows:
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 2;
[locationManager startUpdatingLocation];
Looks like just an informational message from Core Location. It's not crashing your app, the user will not see it and it does still call didFailWithError with the correct error code.
In my tests, the message appears on the iPhone simulator and device (3.1.3) and the iPad simulator but not the iPad device (3.2).
If you're using MapKit as well, this is an error in MapKit. MapKit is registering with Core Location, and then not properly handling the error reported when the user rejects the location update or it fails. It should pass this error on via a delegate method (as it does for geocoding errors), but doesn't.
Unfortunately I can't think of any way to intercept the message from core location, as MapKit maintains an instance of CLLocationManager which it uses to get the location, and that's the one which is reporting the error to its delegate.