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

How to change Device Identity Certificate(SCEP certificate)'s expiration date in OS X Server App(for Profile Manager)
Change background color of title (only) in UIAlertController
Can't Xcode7.1 code sign with certificate?
iOS 8 vs iOS 9 Appdelegate / ViewController method call flow
How to Remove and Adding Constraints when we change simulator orientation(like portrait to landscape) in ios
Parse column value of class is always nil
iOS, Thumbnail from image, Big Nerd Ranch, chapter 19
could not cast value of type UIView to UIButton
iOS Metal buffer not honouring stride value
Regex capture group swift
Scroll Percentage of Cell with offset
Universal layout constraints
any workaround for an Apps using the FB to access an Apps user's friend's friends profile photo and name
App not stopped when launched for background fetch from Xcode
Accelerometer works in first game, but goes crazy in the second
Integration OpenAM - OAuth2 with iOS

Categories

HOME
graph
collections
lua
copy
python-3.5
weight
swashbuckle
stripe-payments
format
delphi-xe7
sony-camera-api
jfreechart
phpmailer
entity
wget
drag
copy-paste
research
openframeworks
vscode-settings
rational
freetype
hp-alm
beanstalkd
dotnetbar
rgdal
bitcode
liferay-aui
jtable
temp
monads
buffer-overflow
breakpoint-sass
dlopen
haxm
outlook-vba
draggable
mask
vue2
sourcetree
uitabbarcontroller
gradle-tooling-api
couchbase-lite
kendo-chart
adal.js
psycopg2
multistore
smartbanner
wrk
android-gps
xbrl
xssf
database-cleaner
flying-saucer
curly-braces
sizing
git-config
business-logic
scrutinizer
facebook-comments
schematiq
post-processor
delphi-10-seattle
quasar
push-api
tabbar
nbug
wss4j
google-swiffy
java-client
horizontalscrollview
information-schema
fig
hebrew
disk-io
jqgrid-php
sqlprofiler
jquery-data
neventstore
cassette
locomotivejs
timespan
eject
clean-urls
rc-shell
maven-bundle-plugin
ondraw
demoscene
arraycopy
net-ssh
posterous
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