Search code examples
iosobjective-cios7background-processmultitasking

Background fetch calling once ios7


This is my first question in SO , sorry if i am not following any guidelines .

I am implementing ios7 background fetch in my older app.But only problem is that i have to do simulate the location in xcode . I have implemented the code like in http://www.objc.io/issue-5/multitasking.html .

My questions are - 1) will this be called regularly (lets say 30 second) on device ? 2) Do i need to simulate background fetch always for testing on device ?


Solution

  • You should use the simulate background fetch feature to verify the logic which is executed upon a background fetch. i.e. whatever code does the fetching.

    You must set the minimum fetch interval. Typically, you’ll set this to UIApplicationBackgroundFetchIntervalMinimum to fetch as often as allowed:

    You can set it like this:

    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
    
        return YES;
    }
    

    The default value is UIApplicationBackgroundFetchIntervalNever, so if you fail to set the value on launching, your app will never be woken up to perform background fetches. The value you provide is the minimum number of seconds between wakes; do note, however, that the value is merely advisory—your application may perform fetches less or more often.

    Setting UIApplicationBackgroundFetchIntervalMinimum will ensure your application is called as regularly as possible, but in reality the system will decide ultimately.


    source