Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a <code>NSNotification</code> with <a href="https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html#//apple_ref/occ/instm/NSNotificationCenter/postNotificationName%3aobject%3auserInfo%3a" rel="nofollow"><code>NSNotificationCenter</code></a>, which fits precisely your purpose :</p> <ul> <li><p>in your AppDelegate, when the sync ends, call </p> <pre><code>[[NSNotificationCenter defaultCenter] postNotificationName:@"SyncEnded" object:mySyncObject] </code></pre></li> <li><p>in every view controller you display, call</p> <pre><code>_myObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"SyncEnded" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note){ ...your UI refresh code... } </code></pre></li> <li><p>also do not forget to remove the observer when it's not needed anymore (view controller deallocated / unloaded / not visible, up to you ), or the <code>NSNotificationCenter</code> will end up crashing :</p> <pre><code>[[NSNotificationCenter defaultCenter] removeObserver:_myObserver]; </code></pre></li> </ul> <p>A few notes :</p> <p>This example uses the block-based API to perform the UI refresh work on the main operation queue (implying on the main thread), because you must not perform UIKit operations on any other thread than the main thread. This is likely that your background sync will send its notification on an other thread, so switching to the main thread is necessary. If you want to use the selector-based API, be sure to send the notification on the main thread.</p> <p>You can register as many observers on the notification as you want, so this matches perfectly your pattern (<code>NSNotifications</code> are usually the best way to notify different app components of an app-wide event like sync end).</p> <p>The <code>object</code> parameter passed when posting the notification allows you to access the sync object in the observer block using <code>note.object</code> if you need it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload