iOS keep gps permission during the session - objective-c

My app loads a jquery + google maps file into webview and when viewDidLoad activates an alert asking for gps accessing (as normal). After validating it, if this view is reloaded later, still pushing the alert! how to keep gps permissions in order to avoid multiple alerts asking for permission? Thank you.

I would try to access the GPS from native Obj-C code first, and after that let the webview to load:
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
[locationManager stopUpdatingLocation];
This should validate your app to use the GPS, and therefore the Webview to use it (at least if it is a local webview, not sure if it is remote).

Related

background location iOS 8

Hello Devs: I am working on an app where I would like to fetch users location in background and send push notifications to him as soon as the user arrives at that particular location. Here is what I have done so far with my locatioManager in my app delegate
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
if (IS_OS_8_OR_LATER) [locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation];
I have set up my info.plist to always request location. I also get the message that my app will be using location in the background when I install the app on my device. However when I close the app and arrive at the specific location I don't get any push notifications or alerts until I launch the app. I turned on Background mode --> location updates under capabilities section and then everything works absolutely fine. I receive notification seamlessly without launching the app. This is all good but when I close the app I see a blue bar on my status bar saying that my app is tracking the location in background. How do I hide that blue bar on the top? I am pretty sure this is going to scare away my users and they will remove my app instantly. To make long story short how do I accomplish this? I know this question has been asked and answered several times in past but all those answers are 2-3 years old and don't seem to work with new iOS 8. I need to get the user location in background in order for my app to work or else its useless. I will really appreciate any help or suggestions to this.
Thanks!
What you want to do is called (background) Geofencing. Your app doesn't need to calculate it by itself since CoreLocation already offers this feature.
Please have a look at this answer from Daniel.
The Geofencing feature will wake up your app when the users gets into the target zone, and will not display the blue bar.

CLLocationManager not getting location without WIFI and Cellular Data

I have implemented Location module by using CLLocationManager but gets some problems.
Getting location finely if device has WIFI or Cellular Data(3G) but when i turn both of them off. Location stop updating i mean on GPS not working.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.distanceFilter = 100.0f;
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
EDIT:
Problem facing on iPhone.
You need to enable cellular data for GPS to work. You don't have to have a cellular signal but the system requires that cellular data be enabled in order to allow location services.
In iOS 4 you used to be able to use location services even in Airplane Mode, by enabling Location Services in Settings after switching to Airplane mode, but this broke in iOS 5.
I've filed a bug report with Apple but they say this is how it is supposed to work now. They try to use cellular and wifi signals triangulation to make corrections to the GPS position.

How to Monitor Location in Background in iOS?

I am currently writing a home automation app for a client which will open their garage, turn on the living room and office lights, and other such things when they arrive within 150 meters of their home. It will do the opposite when they leave. I am very grateful that geofencing is built into iOS, and the feature works perfectly when the app is in the foreground, but when the user closes the app, and the phone is still monitoring a geofence, the app does nothing when an event occurs. Is there a separate method other than locationManager:didEnterRegion: that I should be implementing for background notifications to my app? Here is the code that I am using right now:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(#"Entered Region - %#", region.identifier);
[self showRegionAlert:#"Entering Region" forRegion:region.identifier];
[self sendCommand:true];
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
NSLog(#"Exited Region - %#", region.identifier);
[self showRegionAlert:#"Exiting Region" forRegion:region.identifier];
[self sendCommand:false];
}
To use location services while your app is in the background you need to change your app's info plist file. Should be found in Supporting Files folder and look like this, YourAppName-Info.plist
Add an item to the Information Property List and type in Required Background Modes as the key, which is of type Array. Add an item to that array and type in App registers for location updates into the value of that item.
I discovered it was a non-issue. It all works exactly the same way as if the app were active. The same method is called. I made sure to optimize the app for background launch though so that it would be more of an instant response. I guess I was doing something wrong though, or it just wasn't working at first.
Turn on BackgroundModes in Target Settings/Capabilities and enable Location Updates. Since app is in background, you will get little time for processing and the app will move to sleep mode. Use expirationHandler make app active for some more time for doing large processing.

strange behaviour from Mail and Message controller - pre initialised

I have pre allocated the mail and messaging controllers on startup in my app delegate to save the initialisation time (over 10 secs) when the user is using my application...
__mailController = [[MFMailComposeViewController alloc] init];
__messageController = [[MFMessageComposeViewController alloc] init];
It works fine the first time the controller is displayed then the next time the message is not changed and the old message is still displayed ?? ... Is it likely that the controller is being deallocated ??? Strange as the views work correctly just that the message is not correct ?
- (IBAction)actionSMS:(id)sender {
if([MFMessageComposeViewController canSendText])
{
self.messageController.body = self.MessageDetail.text;
// controller.recipients = [NSArray arrayWithObjects:#"+919999999999", nil];
[self presentModalViewController:self.messageController animated:YES];
}
}
Once MFMailComposeViewController and MFMessageComposeViewController are presented to the user you can't make changes to the content they display.
MFMailComposeViewController Class Reference:
Important The mail composition interface itself is not customizable
and must not be modified by your application. In addition, after
presenting the interface, your application is not allowed to make
further changes to the email content. The user may still edit the
content using the interface, but programmatic changes are ignored.
Thus, you must set the values of content fields before presenting the
interface.
That means those values are somehow locked in the implementation of the MFM*ViewController at the moment you present the controller. So you can't reuse these viewControllers. iOS doesn't care if the controller is, like in your case, invisible or not. If it is presented the content is locked.
I would figure out why it takes 10 seconds to allocate them. And then dump that whole pre-allocation thingie. 10 seconds are definitely to much.
I had the same problem. Not only are the MF controllers only good for one time use, as you discovered, they also cannot be init-ed in the background because their UI elements need to be init-ed in the main thread.
In the end, I just present a UIActivityIndicatorView over a HUD, so the users will know the app is responding.

App Crash on Working with Facebook Connect

While I'm testing my app, is an UITableViewController navigation based app, sometimes, getting back or changing the view for another, I'm getting the next crash message. I can't solve this error, I don't know what is the responsible of this. Somebody can help me?
Thanks for reading.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
When the app has finish, XCode points this Facebook Connect method.
- (void)dialogDidSucceed:(NSURL *)url {
if ([_delegate respondsToSelector:#selector(dialogCompleteWithUrl:)]) {
[_delegate dialogCompleteWithUrl:url];
}
[self dismissWithSuccess:YES animated:YES];
}
Now the problem is solved. The best way to use the Facebook Connect SDK is to implement all the Facebook related objects into the App Delegate. When the user touch the button that allow to post into him Facebook wall (doesn't matter the UIView where the user is), you only have to call the App Delegate and get the Facebook objects that you need to call the Facebook Connect dialog. The App Delegate must be the Facebook Connect delegate for FBDialogDelegate and for FBSessionDelegate. Also, the App Delegate must implement the application: handleOpenURL: method.
Thanks to everyone for reading.