I'm building a native iOS app which is using Salesforce SDK. I'm getting my data using SFRestApi like below.

SFRestRequest *req = [[SFRestRequest alloc]  init];
[req setDelegate:self];
[req setEndpoint:@"/services/apexrest"];
[req setMethod:obj.localOption];
[req setPath:obj.localpath];
[req setQueryParams:obj.dicParam];
[req setParseResponse:YES];
[[SFRestAPI sharedInstance] send:req delegate:self];

and here is my SFRestRequest Delegate Methods

- (void)request:(SFRestRequest *)request didLoadResponse:(id)dataResponse;
- (void)request:(SFRestRequest *)request didFailLoadWithError:(NSError *)error;
- (void)requestDidCancelLoad:(SFRestRequest *)request;
- (void)requestDidTimeout:(SFRestRequest *)request;

These methods are working perfectly. But I'm planning to add new feature "Background Fetch" in my app so I added these lines below in my AppDelegate class.

#pragma mark - AppDelegate Background Fetch
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void     (^)(UIBackgroundFetchResult))completionHandler {

NSLog(@"Fetch started");    
[self.Syncer syncWithOption:SYNC_METHOD_GETSEND]; //This is where I start sync
NSLog(@"Fetch completed");

-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:30];
return true;

Problem is that those 4 SFRestRequest Delegate Methods are not firing when I start background fetching. When I reopen the app, It fires one of those Delegate Methods and continues where it left. Is this an issue about the SDK or should I implement something to make it right ?

1 Answer 1


iOS does not allow access to the keychain while your app is in the background. The Salesforce iOS SDK does not support executing API requests in the background. So if you want to fetch/query Salesforce in the background, you will have to roll your own network calls outside of the Salesforce SDK.

Consider also that you are returning UIBackgroundFetchResultNewData for every fetch request regardless whether there is actually any new data. This will cause iOS to penalize your app, running your fetch requests less frequently.

You are also incorrectly calling the completion handler immediately. You should instead call the completion handler only after your fetch operation has completed.

  • I see. Thanks Jonathan for the response. I will comment out these lines until we have new SF SDK version for this task.
    – Onur Var
    Sep 5, 2014 at 21:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .