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", ¬ify_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 .
Related
The app that I am developing needs access to the photo gallery. I have added the following code to check whether I have access to it.
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
if (status != ALAuthorizationStatusAuthorized) {
NSString *alertMessage = NSLocalizedString(#"PHOTOS_AUTHORIZATION_ALERT_MESSAGE", nil);
dispatch_async(dispatch_get_main_queue(), ^{
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"PHOTOS_AUTHORIZATION_ALERT_TITLE", nil)
message:alertMessage
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK", nil)
otherButtonTitles:nil] show];
});
return NO;
}
return YES;
But sometimes iPhone 5s running iOS 8.4 and always iPhone 6 Plus running iOS 9 does not show my app under the privacy photos list.
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.
I am doing Jailbreak tweak dev for the first time and experimenting with some very simple test tweaks (based on a few tutorials) on an iPhone 5 with IOS 7.0.4 installed. My tweaks compile, link, package and I am able to install on my iPhone. However I cannot get a very basic tweak that links hooks into the SBApplicationIcon working. On the other hand another tweak that hooks into SpringBoard at launch to do the same thing (generate alert) DOES work. So whats going on?? Why is one tweak working and not the other. Have the SBApplicationIcon headers changed in IOS7?? I have a dump of headers from rpetrich's repository
For the tweak that does not work, I have tried adding syslog messages in the code to see if the code is even executed (have syslog enabled on the iphone), but nothing comes up.
Tweak that does NOT work:
#import <SpringBoard/SpringBoard.h>
#import <UIKit/UIKit.h>
%hook SBApplicationIcon
-(void)launch
{
NSString *appName = [self displayName];
NSString *message = [NSString stringWithFormat:#"The app %# has been launched", appName, nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:appName message:message delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
%orig;
}
%end
Tweak that does WORK:
#import <SpringBoard/SpringBoard.h>
%hook SpringBoard
-(void)applicationDidFinishLaunching:(id)application {
%orig;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome"
message:#"Welcome to your iPhone Brandon!"
delegate:nil
cancelButtonTitle:#"Thanks"
otherButtonTitles:nil];
[alert show];
[alert release];
}
%end
-(void)launch has changed to -(void)launchFromLocation:(int)location in iOS7.
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
}
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.