I fired LocalNotification 5 minutes from current time. Then I stopped the application and killed it from background. I received local notification after 5 minutes. While taping on the app icon got opened but didReceiveLocalNotification Method is not called.
Please post some code for better answer.
In the meantime test your app on device.Sometime notification methods working on device but not working on simulator.
use this method
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler{
}
Related
I know there are hundreds of topics out there concerning the background fetch on iOS. I simply cannot solve my problem to get the background fetch for my app to work. It is absoulutely substantial for the outcome of my app to have a working background fetch. My background fetch works fine on the simulator via Debug -> Simulate Background fetch and also on device with the special scheme setting: "Launch due to a background fetch event". I know that it doesn´t gets executed when the user is force quitting the app. I tried to lock the iPhone and wait for hours then unlock it to try to trigger the background fetch. Nothing happens. Actually everything works fine but the background fetch simply NEVER gets executed on my iPhone. I know that iOS has a special algorithm for calling background threads so a little patient is needed. But after 2 months of waiting for a background fetch to happen automatically I don´t have patients anymore. What I did:
App capabilites: Background fetch activated
Info.plist: Required background modes: App downloads content from the network
App delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([UIApplication instancesRespondToSelector:#selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:2.0];
return YES;
}
- (void) application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
//Do my stuff
completionHandler (UIBackgroundFetchResultNewData);
}
Did you check out to go Settings->General->background app refresh and check if its enabled?
It could be the problem...
Could any help in creating a Unity3D App which could request some data from some webservice (let say every 5 mins) and send a local notification while the game app is running in the background.
You can use the AppController class that the Unity player creates. You need to respond to some of these messages:
- (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
These are called when the application goes from the background to active and vice-versa. If you want to communicate with unity, you can pass some info with:
UnitySendMessage("GameObjectName1", "InBackground", "Message to send");
If you send the message in (void)applicationDidEnterBackground:(UIApplication *)application
, the method InBackground() will be called. You can have coroutine in that method with is called in every fixed time. This is a theory. Try to implement it.
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.
I have used VoIP and remote notification as background modes.
I kept my application idle in background for overnight testing.
I have written following code in applicationDidEnterBackground
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{
NSString *message = #"voip keep alive timeout executed....";
NSLog(#"%#",message);
[Logger addEntry:CAT_ML_CORE andSubCategory:SUBCAT_DEBUG andMessage:message];
}];
}
after 1 day keeping application idle in background I found "voip keep alive timeout executed...." got printed in my logs.
This indicated that my app is alive.
But when I send push notification to my app "didreceiveremotenotification fetchcompletionhandler" method doesn't get called.
Which is contradictory to the statement made by Apple "Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running, the system calls didreceiveremotenotification fetchcompletionhandler method regardless of the state of your app. If your app is suspended or not running, the system wakes up or launches your app and puts it into the background running state before calling the method."
Can someone please tell me why this is happening?
Make sure your APNS payload has "content-available"
content-available - number - Provide this key with a value of 1 to indicate that new content is available.This is used to support Newsstand apps and background content downloads.
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
I am making a client server application for the iPhone and would like to know which method is called when the iPhone application is terminated. Any help would be appreciated.
The method relating to application lifecycle are UIApplicationDelegate methods. The two you want are:
- (void)applicationWillTerminate:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
If on a multitasking device, applicationDidEnterBackground: will be called instead of applicationWillTerminate:. In most cases, you can perform the same code in both callbacks.
- (void)applicationWillTerminate:(UIApplication *)application
in your appdelegate
The method applicationWillTerminate gets called when your application is being shut down. But the applicationDidEnterBackground/applicationWillResignActive methods are (now) infinitely more useful.
-(void)applicationWillTerminate:(UIApplication *)application in your application delegate will be called. Check this blog post with chart that describes in detail what messages will be sent during launch, termination and when transitioning between background and foreground.