Background, local update tasks in iOS7 - background

I have a timer related app,that lets the user set timer to different objects.
What I am doing right now -
Right now.I am scheduling a local notification when the timer gets to it's end, and then when the user gets the notification, he needs to open the app so it could process the changes related to this timer.
What I want to achieve -
I have looked on the new iOS7 background modes but could not determine if I can use that to perform those updates to the core data, without opening the app.
So the flow will be:
a timer is coming to it's end.
The user gets a local notification where he needs to permit the operation.
Get the user answer and perform the update while the app is still in the background.
Is that possible with the new API ? Or is it limited to data fetches only ?

If you are you are using Push Notification Using ios 7 new background fetcher api is useful,
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
}
When a push notification arrives, the system displays the notification
to the user and launches the app in the background (if needed)so that it can call this method. Use this method
to download any data related and store to core data to the push notification. When your method is done, call the block in the handler
parameter.

Related

How to detect and implement touch events for single tap on home button?

Not sure if it is possible but is there any way to detect a single touch on the home button. To start with, I would simply like to add an NSLog if the user touches down once on the home button (without actually pressing), but I don't know where I would add this functionality. Does Apple allow you to interact with the home button?
I looked at the app delegate methods, but I can't see how any would work in a single tap (touch) context. Would really appreciate your help.
Does Apple allow you to interact with the home button?
No, not yet. There are no APIs available to explicitly detect home button interactions.
You can rely on the traditional app delegate lifecycle function invocations to perform any logic you wanted to.
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

How get pusher events when the iOS app go to the background?

I need to get triggered eventos from pusher, and when the app go the background I don't get them (only the first one).
I have this:
#property(strong, nonatomic) PTPusherPresenceChannel *taxi_channel;
PTPusherPresenceChannel *taxi = [PusherController sharedApp].taxi_channel;
- (void)viewDidLoad
#weakify(self);
[taxi bindToEventNamed:#"client-driver-cancel-service" handleWithBlock:^(PTPusherEvent *event)
{
DDLogDebug(#"%#: %#", event.name, event.data);
#strongify(self);
[self cancelServiceAcepted];
}];
The problem is that I get a single event when get into the background, but after the first I don't get them anymore.
I have implemented the code at https://github.com/pusher/pusher-test-iOS/blob/master/Diagnostics/Code/ClientDisconnectionHandler.h
If the app go the foreground it work fine.
I'm the author of libPusher. I answered your question on Github but I thought I'd post it here as it might be helpful for others.
Unfortunately its not really possible to use Pusher in the background and its not really what it is designed for. Pusher works great for receiving events in realtime while your app is running but to get background notifications, you really need to be looking at using Apple push notifications OR period fetch, depending on whether you'd prefer push or pull.
My suggestion would be:
Use Pusher while your app is in the foreground to receive real-time updates
Use push notifications to send significant events to your app while it is in the background (these should be less frequent) AND/OR
Possibly use background fetch to pull the latest changes/events from your server
Restart listening to events from Pusher when your app resumes in the foreground

App will be locked if the app is kept in background for 2 min

i am trying to do like Users will be asked for an App Passcode while using the app for first time.
App will be locked if the app is kept in background for 2 min.
User need to provide passcode to unlock the app like banking app.. i don't know how to implement this. As i am new to Ios.
please help me. Thnx in advnce.
In your AppDelegate.m file you'll find these boilerplate methods:
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
You'll want to bring up the password dialog in either WillEnterForeground or DidBecomeActive. Read up on them to see which suits your specific needs.
I did something similar for a client a long time ago. We didn't like the visuals of the dialog appearing when the app became active so we actually brought up the dialog in DidEnterBackground. In our app it just looked better. But these are where you need to start.

UIApplication fixed background fetch interval (private API welcome)

I'm working on an internal app that requires to check the server every 10 mins or so when the application enters background. Normally, I can use APNS when new record arrives.
However, this app will completely skip Apple's garden, so no APN and yes private API.
So the question, is there any way for me to set the background fetch interval directly instead of calling the normal application setMinimumBackgroundFetchInterval:
I also welcome other ideas for the same result.
I recommend implement VOIP background mode, because is simply and provide app wakeup every few minutes. Just set Voice over IP in Background Modes and register handler;
Example:
[[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{
NSLog(#"Here I do something every 600 seconds");
}];
This method more preferable because can work on old iOS, and timeout is fixed vs background fetch where timeout is calculated by user activity and app usage.

Interrupted method when user pushes home button?

What happens when a user pushes the home button on the iOS device and the app is currently running a method: Will the method finish running or will the method be interrupted in the middle?
Like Maudicus wrote, applicationWillResignActive: is called on the application delegate, as well as applicationDidEnterBackground:. You should assume that any method that is currently running will be interrupted. If you want to ensure that a particular operation is performed, you should put it in one of the aforementioned methods.