3

I recently decided to make my move to StackMob (from Parse). I have managed to setup core data and i can read and write to StackMob datastore.

So far, StackMob offers a list of item to the user. If the user decides to user an item on my app, I want the item to be available offline, so he can use it without having to connect to stackmob.

I am thinking of creating a local Core Data and copying the items that the user select there. My first problem is if i could use the same object for both Core Data (stackmob and local). And if this is the right approach to follow.

zirinisp
  • 9,971
  • 5
  • 32
  • 38

1 Answers1

2

The latest sdk includes support for caching of core data. Details are In this blog post.

The caching system is off by default. To turn it on, simply set the SM_CACHE_ENABLED flag to YES in your App Delegate file, before you initialize a Core Data store. The flag is declared in SMCoreDataStore.h.

It also includes this code example for how to control the cache...

SMClient *client = [[SMClient alloc] initWithAPIVersion:@"0" publicKey:@"XXXX"];
SMCoreDataStore *coreDataStore = [client coreDataStoreWithManagedObjectModel:myModel];
[client.session.networkMonitor setNetworkStatusChangeBlockWithCachePolicyReturn:^SMCachePolicy(SMNetworkStatus status) {
        if (status == Reachable) {
            return SMCachePolicyTryNetworkElseCache;
        } else {
            return SMCachePolicyTryCacheOnly;
        }
}];
msv
  • 163
  • 3
combinatorial
  • 9,132
  • 4
  • 40
  • 58
  • How is this parameter (SMNetworkStatus status) passed into the block? Or "SMNetworkStatus status" is a kind of global instance? Thanks. – J-Q Aug 24 '14 at 01:52
  • 1
    By the sdk, not sure how. But you know stackmob has been shutdown after being purchased by PayPal? – combinatorial Aug 24 '14 at 03:59
  • Yes, I just knew it this week, Big brother choked it to death by May 11th 2014. Since nowhere to get its SDK tutorial downloaded, I searched StackOverflow and found your reply here. I was still wondering if there is an iVAR "SMNetworkStatus status" inside "@interface SMNetworkReachability : AFHTTPClient" hidden in .m file, since this "SMNetworkReachability" class has a "- (SMNetworkStatus)currentNetworkStatus;" public method, which really looks like a Getter after facelift. Thanks for your response! – J-Q Aug 24 '14 at 04:22
  • 1
    I am pretty sure it used the standard Apple reachability code... https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html – combinatorial Aug 24 '14 at 18:21
  • I have to agree. Very likely, it was the "SCNetworkReachabilityCreateWithAddress" got the job done. Thanks David! – J-Q Aug 25 '14 at 04:37