I am new to location based applications.
My requirement is, device has to show the location based notifications when the user reaches the selected region.
I implemented perfectly. This app is working on background also.
Now my new requirement is, device has to show the location based notifications even after kill the app. [I saw a couple of iPhone apps working with this functionality. The apps are "Reminder" & "Locationizer" ] .
Can you please check my implementations steps as follows.
Launch the application.
Selected the location alert button.
Called the following CLLocationManager API's to monitor my region.
[locationManager startMonitoringForRegion:#"MyRegion" desiredAccuracy:kCLLocationAccuracyBest];
[locationManager startMonitoringSignificantLocationChanges];
Quit the app [Running in background].
I am getting location based alert notifications properly.
Here the new requirement.
Launch the application.
Selected the location alert Button.
Called the following CLLocationManager API's to monitor my region.
[locationManager startMonitoringForRegion:#"MyRegion" desiredAccuracy:kCLLocationAccuracyBest];
[locationManager startMonitoringSignificantLocationChanges];
Kill the app. [now application is not running in background]
App should show the location based notification when user reach the location.
How do I implement this logic?
Hi Friends I found solution for this issue.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue)
{
[self initLocationMonitoring]; // this will invoke CLLocationManager
}
return YES;
}
An app that is quitted cant perform any functioning...so i will suggest to recheck those apps ..they must be functioning in the background to check the location of the device...they won't be able to alert if they are quitted.
Related
didReceiveLocalNotification is called when a notification is fired in active mode but how does iOS handles notification in background mode (not active mode, application is terminated may be) before app is active by swiping or clicking the notification.
Or
Mainly I want to know how to conditionally handle local notification to be on/off (off means not to cancel previous notification but just don't fire it) in background Mode?
I am currently checking this condition in didReceiveLocalNotification but that way I am not able to handle it in background mode?
You can check that is your app started by clicking on local notification in didFinishLaunchingWithOptions method in AppDelegate.m file.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif)
{
// your code
}
}
If application is running Alerts won't be shown automatically - you have to handle that manually using the functions you mentioned.
When application is in background or not running iOS will show your local notifications in notifications center and present them according to user settings - as a banner or alert.
Best read this:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html
When your app is in the background iOS will handle the notification (Local or Push) and your app can not access them at all.
Only after your app is started will you be able to direct if the user select a notification.
I am scheduling a local notification which is firing fine. I need to know how to allow a user to launch my app after the notification has been displayed on screen.
I also need to know how to identify this type of launch to direct the user to a specific view, relevant only to users who have arrived as a result of the notification.
I have been looking at the UIApplicationDelegate protocol reference and feel it could be in the area of the launchOptions within -didFinishLaunchingWithOptions:, but need a little pointer.
Your application will launch automatically, you don't have to do anything in the app itself for that to happen.
If that's not already happening, check that you've specified an alertAction for the notification when you create it - that's the label of the button in the notification alert that opens your app and if you don't set it, the notification alert won't launch the app.
To open a specific view, use the launchOptions and the application:didReceiveRemoteNotification method.
didFinishLaunchingWithOptions: would do the trick.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
// .. etc
};
Keep in mind you also need to implement
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
if you receive a push notification while the app is running (fore- or background)
The launch options should contain the key UIApplicationLaunchOptionsLocalNotificationKey which in turn gives you the UILocalNotification associated with the notification. Additionally, when scheduling the notification your UILocalNotification has the properties alertBody, alertAction and optionally alertLaunchImage which control the information being displayed. The action decribes the button text that launches your app while the body is the information being deisplayed above the buttons. You can supply a specific launch image for this launch to mimic the app already being run.
Also note Bogatyr's answer concerning the cases where your app is not being launched but already there, just suspended.
I have an iOS application that uses GPS for Location Services. A user would like to use the app on an iPod Touch with an external GPS, but the problem is that the user can't enable Location Services in Settings->General Settings->Location Services for this app.
When the app is run on an iPhone, in Settings->General Settings->Location Services, the app shows up with a toggle switch to enable/disable Location Services for this app. But when the app is run on an iPod Touch, the app doesn't show up in Settings->General Settings->Location Services.
Does anyone know what I need to do programmatically to cause Location Services for this app to show up with a toggle switch in Settings->General Settings->Location Services when run on an iPod Touch?
I think that the ability comes when CLLocationManager is implemented for the first time. I'm not sure if that is what's used with an external GPS receiver but if you're getting the Lat/Long from the GPS, you can send those coordinates to the location manager.
I figured out what the problem was. I had the following code that only allowed Location Services for iPhone and not for iPod. Oops!
if([model hasPrefix:#"iPhone"]){
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 10.0f;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
self.locations = [NSMutableArray arrayWithCapacity:32];
}
I am making an application in which have to show user current location on map with some time set, i have worked on that and it is working for me, however if i leave the app open and after 5 minutes app goes to inactive state i stop the location update and after 5 minutes if i again relock the slider and check the app, it comes into active state , have called location update and show the current location, however few times it got crashed from inactive to active state
- (void)applicationWillResignActive:(UIApplication *)application {
[locationManger stopUpdatingLocation];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
locationManger.delegate = self;
[locationManger startUpdatingLocation];
}
If you only have to show the user's location on the map, then you dont need CLLocationManager. Just use
mapView.showsUserLocation = YES;
I have tried the launch the settings of iPhone in my application using the call
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
[locationManager release];
but I was able to launch only once,now I am not able to launch the settings in my application.
I am using iPhone 3GS with iOS 4.2
Is there any other way to launch settings any no of time if the location services are off.
but I was able to launch only once,now I am not
If you saw an alert kind of msg on your app asking for your permission for using yous gps location. Then this is the default behavior of iPhone OS. if you try to get gps location in any app the OS ask for user's permission. You can not launch this alert again!
but if you wants to change the setting (means wants to enable or disable the location tracking) then you can open the "Settings" application and look for location services setting. You can find your app there and disable the location tracking. But remember you can not open the "Settings" app using your app.
Now this issue is not in iOS5.
If you are calling startUpdatingLoaction method as below code and if location service is off,the system alert will popup and if you tap setting button,it will navigate to phone settings screen. And in phone setting screen you can switch on the location service.
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];