Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8527693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:37:41+00:00 2026-06-11T08:37:41+00:00

I’ve written a synchronisation class for the app I’m currently working on. Because of

  • 0

I’ve written a synchronisation class for the app I’m currently working on.

Because of the large amount of data it first gets a data count and then batches up the downloads in an NSOperationQueue. This all works fine and I’ve got the sync algorithm working quickly.

The way it works is as follows…

- (void)synchroniseWithCompletionHandler://block for completion handler
                            errorHandler://block for error handler
{
    [self.queue addOperationWithBlock
     ^{
           //Create an NSURLRequest for the first batch
           //Send the request synchronously
           //Process the result
           //If error then cancel all operations in the queue, run errorHandler and return.
      }];

    [self.queue addOperationWithBlock
     ^{
           //Create an NSURLRequest for the second batch
           //Send the request synchronously
           //Process the result
           //If error then cancel all operations in the queue, run errorHandler and return.
      }];

    //Add all the remaining batches.

    [self.queue addOperationWithBlock
     ^{
           completionHandler();
      }];
}

This works and keeps the memory usage to a minimum and speed to a maximum. The idea is that the download and process are both in the same block and both processed before moving on to the next operation in the queue.

Except, we have now implemented OAuth2 on the server to authenticate the calls.

I have got this working by setting up an NXOAuth2Request through the NXOAuth2 library. Then setting the account and pulling out the signed URL request. Then I use this NSURLRequest as I was doing previously.

The problem with this is that if the OAuth token expires half way through the sync then the sync fails.

The NXOAuth2 library has a function…

+ (void)performMethod:(NSString *)aMethod
           onResource:(NSURL *)aResource
      usingParameters:(NSDictionary *)someParameters
          withAccount:(NXOAuth2Account *)anAccount
  sendProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)progressHandler
      responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler;

This handles the situation of an expired token by resending the request after doing a token refresh.

However, this function is asynchronous so I’m not sure how best to fit it in to my sync program.

I could just add the operations using this and then put the processing into the completion block. But doing this means that all the downloads will pretty much run all at the same time and then there’s no way of guaranteeing the order in which the downloads get processed (I need them to be processed in a strict order due to data dependencies.

The only way I can think of doing this now is to daisy-chain them all together…

[NXOAuth2Request performFirstRequest...
    {
        deal with the data.
        [NXOauth2Request performSecondRequest...
            {
                deal with the data.
                [NXOauth2Request performThirdRequest...
                    {
                        deal with the data.
                        finish
                     }];
             }];
      }];

And this is just messy and could get VERY messy.

Is there any other way I could process this at all? The only other thing I can think is to try and do the refreshing myself.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:37:42+00:00Added an answer on June 11, 2026 at 8:37 am

    While I love blocks there are just some tasks best done with concurrent NSOperations. I put a really simple really easy to adopt project on github, using the EXACT same files I use in my apps in the store, to fetch and process data. You could easily adapt this same strategy to your task.

    • you start with a base concurrent operation that does a web fetch, gets some data.
    • with a subclass you can process that data in different ways
    • since its concurrent, meaning it has its own runloop, it can block waiting for messages so you can incorporate you authorization within it
    • you can use whatever logic you want – if you get an authorization failure in the middle, you could cancel your url request, authorize, then do another all within one operation
    • you can chain operations so that you never have more then one active at a time

    I’m using this structure for all my web interactions, and have something like 30 subclasses the do different types of processing on the received data.

    The project has three primary classes:

    • OperationsRunner – a really small class that provides a high level interface to NSOperationsQueue

    • ConcurrentOperation – the bare minimum

    • WebFetcher – a class that runs a NSURLConnection and completes when it does

    Other subclasses need only supply a “complete” method to process data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I want to construct a data frame in an Rcpp function, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.