ios


Core Data App group synchronization (w/ extension)


The widgets in our iOS App are custom, and therefore I added a feature to remove parts of the widget. To save settings for the widgets etc. our widgets share Core Data via App groups. However when I delete something from the widget it doesnt seem to always sync correctly. This happens primarily when the app is active in memory.
When I delete something I call this:
-(void)removeWidgetFromUser:(UserModel *)user Widget:(Widget *)widget{
if(widget != nil){
[widgetContext deleteObject:widget];
NSError *error;
if (![widgetContext save:&error]) {
NSLog(#"Unable to remove widget %#", error);
}
}
}
Then I use wormhole to sync the core data in my app and it calls this:
-(void)updateCoreData{
[self.managedObjectContext refreshAllObjects];
}
I am sure both the methods get called. But sometimes the app sees a widget I just removed, and then it also happens to reappear in my Widget.
EDIT:
I think whats happening is that the CoreData context in my app doesnt update correctly and then the widget actually syncs with the CoreData in my app. Therefore the deleted widget re-appears after some time. Still figuring it out...
I finally did it. By implementing the following code:
- (id)initWithCoder:(NSCoder *)decoder {
NSManagedObjectContext *context = [SharedCoreDataObjects sharedInstance].managedObjectContext; // use your NSManagedObjectContext
NSPersistentStoreCoordinator *coordinator = [SharedCoreDataObjects sharedInstance].persistentStoreCoordinator; //use your NSPersistentStoreCoordinator
NSURL *url = (NSURL *)[decoder decodeObjectForKey:#"URIRepresentation"];
NSManagedObjectID *managedObjectID = [coordinator managedObjectIDForURIRepresentation:url];
self = [context existingObjectWithID:managedObjectID error:nil];
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:[[self objectID] URIRepresentation] forKey:#"URIRepresentation"];
}
in my NSManagedObjects I was able use MMWormhole to send the NSManagedObjectContextDidSaveNotification
to the App and then call
[context mergeChangesFromContextDidSaveNotification:messageObject];
To let the context merge the changes. This seems to work perfectly for now!

Related Links

Run MQTT Broker in iOS
how to rotate image to a particular latitude and longitude in swift?
how to add json file in ActionRequestHandler safari extinction
How do I make a control on a reused custom UIView trigger actions only on the ViewController currently being viewed?
NSPredicate SUBQUERY with nested arrays iOS Objective C
What delegate method will be called on receiving a push notification if the app is in killed/Force closed (Not in background) state?
didReceiveMessage not called after unlocking the iPhone screen?
How to access source view that perform segue from within that segue or destination view controller?
I want to use same UserInterface with different Data in ios
IQKeyboardManager not working when UITableView embedded in a container view
How to save image from camera/photo library into an array that is to be displayed in a UICollectionView
Adding target to UIControl
Uploading multiple builds of same iOS Application
Swift json delete key
Delay start of animation for UIView with CAKeyframeAnimation?
Why does an NSObject have to be initialized before its' .class-property is readable

Categories

HOME
html5-canvas
graph
mongodb
whatsapp
x-editable
compiler-errors
haskell-stack
prometheus
jqgrid
weblogic11g
spacemacs
autofac
drag
oracle-ucm
editor
angular-components
abaqus
ghost-blog
django-autocomplete-light
amazon-cloudfront
c-strings
zos
precision
code-signing
sumifs
f2py
jsplumb
dlopen
imageshack
mobilefirst-bluemix
tensor
gridstack
bits
vtable
angular-xeditable
azure-management-api
wp-api
couchbase-lite
php-deployer
sql-insert
domdocument
koala-framework
jahia
haste
gpt
bosh-deployer
breach-attack
pypyodbc
mongolab
trello.net
id3
hl7-v2
jedi
openocd
cvc4
gem5
abort
ehcache-bigmemory
windows-universal
alt
applicationstate
spiceworks
knockout-mvc
httpservice
datacontractserializer
globus-toolkit
django-supervisor
mouseenter
asp.net-apicontroller
validform
mongo-shell
confirmation
shift
gora
xcache
source-highlighting
neventstore
locomotivejs
stumbleupon
measure
renderaction
xoom
spquery
ryz
non-relational-database
usenet
case-tools
graceful-degradation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App