Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TC-1101] Added Ti.App.Properties 'change' event for iOS #2635

Merged
merged 2 commits into from
Jul 31, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions iphone/Classes/TiAppPropertiesProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,33 @@ @implementation TiAppPropertiesProxy

-(void)dealloc
{
TiThreadPerformOnMainThread(^{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}, YES);
RELEASE_TO_NIL(defaultsObject);
[super dealloc];
}

-(void)_listenerAdded:(NSString*)type count:(int)count
{
if (count == 1 && [type isEqual:@"change"])
{
TiThreadPerformOnMainThread(^{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(NSUserDefaultsDidChange) name:NSUserDefaultsDidChangeNotification object:nil];
}, YES);
}
}

-(void)_listenerRemoved:(NSString*)type count:(int)count
{
if (count == 0 && [type isEqual:@"change"])
{
TiThreadPerformOnMainThread(^{
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSUserDefaultsDidChangeNotification object:nil];
}, YES);
}
}

-(void)_configure
{
defaultsObject = [[NSUserDefaults standardUserDefaults] retain];
Expand Down Expand Up @@ -150,6 +173,11 @@ -(id)listProperties:(id)args
return [[defaultsObject dictionaryRepresentation] allKeys];
}

-(void) NSUserDefaultsDidChange
{
[self fireEvent:@"change" withObject:nil];
}

@end

#endif