I can't fetch data in background in iOS - ios

My app does the intended operations when I use Simulate Background Fetch in the Debug tab in Xcode, however, when the app is running on my phone nothing works.
Has this happened to someone before? How did you resolve it?
I'm currently using Swift 2.2 and Xcode 7.3

Did you edit the schema in Run mode for the Launch due to a Background Fetch Event
iOS Background Fetch Not Working Even Though Correct Background Mode Configured

iOS won't allow any app to run in the background unless the app ask for it and it will allow it to run for 10mins only to register for background execution:
- (void)applicationDidEnterBackground:(UIApplication *)application {
UIBackgroundTaskIdentifier identifier;
identifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:identifier];
}];
}

Related

Notification count showing when application is installed in iOS

When application is installed for the first time I am seeing notification badge count as 1 by default. I am not able to find from where it is coming.
I tried many approaches provided over SO, but none of them worked for me.
Add this code in your AppDelegate.m
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

iOS 9.2.1, cancel notifcation not working

I'm developing an app having local notification scheduled.
I'm not able to cancel the scheduled notification using the code:
UIApplication *app=[UIApplication sharedApplication];
[app cancelLocalNotification:notification];
The code is working well in previous iOS versions, but it is stopped working in iOS 9.2.1 update.
Can anyone please help me to sort out the issue?
There is a bug in iOS 9.2.1, so cancelLocalNotification methods doesn't work sometimes.
Use cancelLocalAllNotifications and update your logic accordingly.
This should work.
Keep your localnotification object in NSUSerDefault when it is scheduling, even if your device gets restart you can retrieve localnotification object from NSUSerDefault. So then after you can easily pass that object in cancelLocalNotification(localNotificationObject) and remove it.

iOS7 background fetch performFetchWithCompletionHandler does not work on device when not connected to xcode debug mode

I implemented the performFetchWithCompletionHandler for background fetch. I have local notifications setup to fire when there is change in data. For test purposes I also had notifications to fire even when there is no change in data so that I know things are actually working, and I don't have to wait for remote data to change to test my app).
With the app in debug mode in xcode, I use the "Simulate Background fetch" option, and background fetch works as expected. Notifications are displayed on the simulator as expected.
Deleted the old app on the phone. I connect the ip5 device to xcode and run the app. App is updated on iphone. When in debug mode, I execute the "Simulate Background fetch" option. I see local notifications as I expected.
now I have disconnected the device and I have been opening and closing the app every hour (amlost!), but background fetch has not fired even once, and I have not seen any local notification yet.
I have set the code to do this:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
return YES;
}
What am I doing wrong?
In Xcode 5 Debug mode, you can force a background fetch from the menu: Debug > Simulate Background Fetch.
Please check this link
performFetchWithCompletionHandler never gets fired
Hoping that this is not the case:
What type of background fetch are you doing? It is possible that the fetch may work once in the debugger and not again - and then when you run an actual IPA, because you are, for example, doing a dataTaskWithRequest or something similar - that it won't work.

App be killed in the background running in iOS 7

My app uses CoreBluetooth to connect a BLE device, also adds the UIBackgroundModes (the value "bluetooth-central") in the info.plist. When the app into the background, app can continue to read the RSSI Value from a connected device. But app be killed in the background every time after several minutes. I uses instruments tool to test the live bytes, the total bytes about 12MB. Test the app in iphone4s,iphone5,iphone5s, there are such problems. So I don't know how to resolve it? My app requires the long time running in the background. Everyone has other ideas?
I think you should start a background task.
UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier taskIdentifier = [app beginBackgroundTaskWithExpirationHandler:^{
// Cleanup before closing app
}];

ApplicationIconBadgeNumber is not getting reset on reinstallation of my ipad app.

I'm setting my applicationIconBadgeNumber using this code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:theIntToDisplay];
The problem is that when I delete the app from an iPad and reinstall it, the app icon still shows the previous badge number. Is this default iOS behavior or can we reset it?
I found one similar question on at Why the applicationIconBadgeNumber is not getting deleted with appliccation ? Where it stored actually?, but it didn't answer my question.
This is an expected behavior, the badge number remains for a short period after uninstall e.g for the case of an immediate re-install.
Of course you can nullify badge number after every launching the application in application:didFinishLaunchingWithOptions: method but I think it is not the case because you want badge number not to be shown right after you install app and not yet launch it. In such a case just wait after removing the application and the badge numbers cache will be cleared by iOS and then install the app again. Unfortunately without jailbreaking the device there is no way to manage badge numbers behavior manually
In your app delegate under:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
Insert:
application.applicationIconBadgeNumber = 0;

Resources