Local notifications on gps services off - ios

I am using location services on background in my app for fetching user location.
I want to get local notifications from my application when the user switches off the location services in settings page.
Thanks in advance!!!!

Try This :
It's called every time user disable/enable location services in settings
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;

Why you want to use local notification? Why not UIAlertView?
I would like to suggest you to use UIAlertView as it will inform the user what to do when he/she opens the app. For local notification, you can schedule it. Most likely, the user will not see the notification when the user is on the foreground of the app (when open). And you are not able to know if the app has the right to use location or not if the user never opens the app.
By using didFailWithError delegate method from locationManager, you will be able to know if the user allows your app to get the location or not.
You will have to implement the locationManager delegate method like below:-
- (void)locationManager: (CLLocationManager *)manager didFailWithError: (NSError *)error
{
switch([error code])
{
case kCLErrorNetwork: // general, network-related error
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Network Error" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
break;
case kCLErrorDenied:{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"YOUR APP NAME doesn't work without Location Services enabled. To turn it on, go to Settings > Privacy > Location Services" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
break;
default:
{
}
break;
}
}
If you insist want to implement local notification, replace the above UIAlertView with local notification code.

Related

How can I track iPhone usage like the 'Moment' app does?

How to track total usage of iPhone, even if our app is running in background(not forcefully terminated). Recently i have come across app, namely
Moment this app does track your iPhone usages, even if this app is running in background. actually they are using location service to get execution time. my question is when they get execution time, how they can be sure if user's iPhone screen lock or unlock ?
i have code to check if screen is lock or unlock
-(void)registerAppforDetectLockState {
int notify_token;
notify_register_dispatch("com.apple.springboard.lockstate", &notify_token,dispatch_get_main_queue(), ^(int token) {
uint64_t state = UINT64_MAX;
notify_get_state(token, &state);
if(state == 0) {
NSLog(#"unlock device");
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:#"unlock device" message:#"test" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
} else {
NSLog(#"lock device");
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:#"lock device" message:#"test" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
});
}
but this code is working only when app is running in foreground.
Your code is working only when app is running in foreground because when app goes in to background it is not called you have to use one of the background mode to wakeup your application can execute your code .

Change Page / View in iOS

I have written a function to login to a web service using objective c
- (void) registerAck: (NSNotification *) notification {
NSLog(#"Detected callback for register");
NSString *status = [[notification userInfo] valueForKey:#"result"];
if([status rangeOfString:#"Successful"].location != NSNotFound){
//succesfully registered
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome"
message:#"Thank you for registering. Please login using the created details"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[[NSNotificationCenter defaultCenter] removeObserver:self];
NSLog(#"%#", status);
}
I want to know how I would go about clearing the page and then when the user selects ok on my popup chaining the page to a different one?
The clear page is easy, I would just write a method and then call this before alert[show] but the change of page is where I am stuck - can anyone let me know how I could redirect to a login page programatically?

How can I tell if my device doesn't see beacons?

I'm creating an iOS 7 app that will react to nearby beacons. However, I need to consider users that have an iPhone 4 or any other device that will not detect beacons. How can I tell if the device my app is running on supports beacons?
you can use CBCentral manager state. If it is CBCentralManagerStateUnsupported it doesn't support BLE.
If you want to monitor or range for beacons you might want to check if monitoring is available via CoreLocation Framework - Here is the way to do it :
if (![CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Monitoring not available" message:nil delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[alert show];
return;
}
else{
//Monitoring is available
}

didReceiveLocalNotification not active in iOS6

Recently I am trying to create an alarm clock, and when I use UILocalNotification, the problem occur. It will show a banner when the app is in background, but when the app is active, even thought I have used didReceiveLocalNotification, there is no reaction at all.
Why?
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = application.applicationState;
if (state == UIApplicationStateActive) {
NSLog(#"RingRingRing~~~~~");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Remind" message:notification.alertBody delegate:self cancelButtonTitle:#"Sure" otherButtonTitles:nil, nil];
[alert show];
}
}
Neither Remote or local notifications does not wakeup the application in iOS. it takes a user's action on the notification to launch the app.

Apns-alert customization

I have successfully used APNS in iphone app and still have a problem the alert customization.Below is my question:
1 I can't custom the Alert view,like title and button title.I custom the alert like:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSDictionary *apsDic = [userInfo valueForKey:#"aps"];
NSString *alertStr = [apsDic valueForKey:#"alert"];
NSNumber *badgeNum = [apsDic valueForKey:#"badge"];
NSString *soundStr = [apsDic valueForKey:#"sound"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[arr objectAtIndex:1]
message:msg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"view",nil];
[alert show];
[alert release];
}
In my App, the title of the alert is my app's title;and the button titles are "Close" and "View".
2 when I click the "View", is shows the launch view of my app and then it crashes.Why?
So if the alert is provided by the system which can't be customized, the view action is also under control of system. It seems there's contradiction between 1 and 2.
Any help is appreciated!
thanks
I find: if your app does not start, the apns-alert is provided by the iOS which you can't customize.

Resources