Managing Requests

The SalesforceNetwork library for iOS defines two primary objects, SFNetworkEngine and SFNetworkOperation. SFRestRequest internally uses a SFNetworkOperation object to make each server call.

If you’d like to access the SFNetworkOperation object for any request, you have two options.

  • The following methods return SFNetworkOperation*:
    • [SFRestRequest send:]

    • [SFRestAPI send:delegate:]

  • SFRestRequest objects include a networkOperation object of type SFNetworkOperation*.

To cancel pending REST requests, you also have two options.

  • SFRestRequest provides a new method that cancels the request:
    1- (void) cancel;
  • And SFRestAPI has a method that cancels all requests currently running:
    1- (void)cancelAllRequests;

Examples of Canceling Requests

To cancel all requests:

1[[SFRestAPI sharedInstance] cancelAllRequests];

To cancel a single request:

1SFRestRequest *request = [[SFRestAPI sharedInstance] requestForOwnedFilesList:nil page:0];
2[[SFRestAPI sharedInstance] send:request delegate:self];
3...
4// User taps Cancel Request button while waiting for the response
5-(void) cancelRequest:(SFRestRequest *) request {
6   [request cancel];
7}