iPhone app crashes when asking for Location Services permission - iphone

My app has a button, which, when tapped, gets the phone's current location and appends the CLLocation object's timestamp (NSString) to another string.
the first time the user uses the app and calls this method, the app crashes:
'NSInvalidArgumentException', reason: '* -[__NSCFConstantString sringByAppendingString:]: nil argument'
which I can understand, because the app doesn't have permission to use Location services yet and the timestamp is still nil.
At same time, after the app has crashed, the user is asked for permission, and this problem disappears once the user gives the app permission to use Location services.
How can I stop the app from crashing the first time ?
i've tried to get the current Location in viewWillLoad if [locationManager authorizationStatus] != authorised, but the notification asking for permission only appears instantly.
Thanks for helping !!

To make sure you are using a nil when there is risk of raising an exception you can check for nullity very simply:
if(stringToAppend) {
// Do something with the string
}
That way if the object is nil, the risky code won't be executed and the app won't crash.

Related

App terminates on run

I am making an app in Swift and Xcode 6 and everything has been working fine, until now. When I go to run it, I get a delegate error and it crashes immediately. Here is the debugger code:
2014-11-11 10:18:48.282 Pro Cast[2987:65789] *** Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'You have to call setApplicationId:clientKey: on Parse to configure Parse.'
I've never had an issue with Parse up tot his point. What can I do?
You need to set your Parse applicationID and clientID in the AppDelegate.m. Specifically in didFinishLaunchingWithOptions You can get your appID and clientID on the parse website.
Don't forget to import the parse framework.

why CLLocationManager always returns true?

I am using [CLLocationManager locationServicesEnabled] function to get the status whether location service is enabled or not. I kept code in viewDidLoad method.
if(![CLLocationManager locationServicesEnabled])
{
NSLog(#"No");
}
else
{
NSLog(#"Yes");
}
When I am running this app first time it returns Yes. Why? It should return me No. This is the case when I did not select "Allow" or "Don't allow" options. Means I neither allow nor don't allow but in viewDidLoad I got Yes.
Now I select "Don't allow" and again load the same viewController. At this time at least it should return me No, but still I got Yes. Why?
So much of confusion with CLLocationManager.
Any ideas?
locationServicesEnabled returns whether location service is enabled on settings.. If it is enabled in settings, this function returns YES all the time..
from documentation
locationServicesEnabled
Returns a Boolean value indicating whether location services are enabled on the device.
Discussion
The user can enable or disable location services from the Settings
application by toggling the Location Services switch in General.
You should check the return value of this method before starting
location updates to determine whether the user has location services
enabled for the current device. If this method returns NO and you
start location updates anyway, the Core Location framework prompts the
user to confirm whether location services should be reenabled.
Whether or not user allowed/rejected app permission (in the alertview) doesn't affect the return value of this method.
If you want to know whether user has given application permission to access location, you can use authorizationStatus.

App Crashes After Facebook Login

i made an iphone App which I've submitted in the App store . The App is there in the App Store for about an year . It has basically a faceBook Login button . One fine day it crashes, the moment i click my Facebook login Button in my iPhone 4, iPhone 4s.When i try to run it in my Macbookpro it also crashed . I'm getting the error
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull lowercaseString]: unrecognized selector sent to instance 0x2125ce8'".........
It works fine in my iPhone 3Gs...please help me .How can a iPhone App crash After working fine for about an year. Is it something related to Facebook updated methods or related to iPhone version.The App crashes exactly after FBrequest is called !please help me I'm losing my reputation .......
Looks like there is a string in your app that is set to point to NSNull. The app crashes when you are attempting to make that string lowercase.
Since NSNull points to a static object of type NSNull, trying to send the message "lowercaseString" to it causes the app to crash. (if it had been nil, Objective-C would simply ignore the message)
Could it be that there is a string somewhere that used to be set to a value, but for some reason now has been removed and is set to NSNull? It could be due to changes in the FaceBook-API but it could also be caused by changes in what the server is sending to you, different information in your facebook account and many other things. The parser you are using may be setting NSNull instead of nil whenever a NULL-value is sent by the server.
Bare in mind that it might also not be related to Facebook at all, since you find different behaviour on iPhone3GS.
You could try to look around for NSString values in your code that you are trying to make lowercase. Use the debugger to try to identify strings that are of type NSNull. You can compare your strings to NSNull like this:
if (text == (id)[NSNull null]) {
// String is NSNull!
}

"Don't Allow" in LocationManager keeps logging errors

I have an app that checked for location. It asks the user to use location and if the user says no on the menu there is an issue when i load the mapview.
Once i select the mapView it asks for the user location again. If the user says no again my console keeps displaying errors/warning as well as my NSLog from the "didFailWithError" of my location Manager class.
Is there a way of stopping the LocationManage:didFailWithErrors if the user has already said no? I don't think Apple would accept my app if the Log file gets filled up my the LocationManager
Here is an example of what gets repeated in the console
ERROR,Time,290362745.002,Function,"void CLClientHandleDaemonDataRegistration(__CLClient*, const CLDaemonCommToClientRegistration*, const __CFDictionary*)",server did not accept client registration 1
WARNING,Time,290362745.005,Function,"void CLClientHandleDaemonInvalidation(__CFMessagePort*, void*)",client 1035.0 has been disconnected from daemon
2010-03-15 12:19:05.002 SAQ[1035:207] LocationManager Error Denied by user
Documentation on -didFailWithError: method says:
If the user denies your application’s
use of the location service, this
method reports a kCLErrorDenied error.
Upon receiving such an error, you
should stop the location service.
So after receiving this error you should message you location manager to stop updating location:
[manager stopUpdatingLocation];
If you're using MKMapView I think setting its showsUserLocation property to NO should do the trick.
It is your responsibility to check the error code and stop updating the location if the error code is kCLErrorDenied.

check if a user allows the app to use their location

The first time the app tries to get the users location they are prompted with "Would like to use your current location" and they can hit Don't allow or ok. Is there any way to find out if the user has hit ok or don't allow? I'm trying to have the MKMapView show the users current location but I would like to take different actions based on the users selection.
Normally you would think there would be a delegate to get this information but there doesn't seem to be.
Thanks in advance for your help.
Your first call to get the user's location will fail with an error which tells you the user has denied location services. Your CLLocationManagerDelegate method didFailWithError will be called, as below. (The constants are defined in CLError.h)
- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError
{
switch([anError code])
{
case kCLErrorLocationUnknown: // location is currently unknown, but CL will keep trying
break;
case kCLErrorDenied: // CL access has been denied (eg, user declined location use)
message = #"Sorry, flook has to know your location in order to work. You'll be able to see some cards but not find them nearby";
break;
case kCLErrorNetwork: // general, network-related error
message = #"Flook can't find you - please check your network connection or that you are not in airplane mode";
}
}