Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #480 from aaronraimist/nsuserdefaults-synchronize
Browse files Browse the repository at this point in the history
Remove all calls of [NSUserDefaults synchronize] (#1924)
  • Loading branch information
manuroe authored Oct 16, 2018
2 parents 9273fe3 + 149cb69 commit 2a57b54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
23 changes: 5 additions & 18 deletions MatrixKit/Models/Account/MXKAccountManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ - (void)logoutWithCompletion:(void (^)(void))completion
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kMXKAccountsKey];
[sharedUserDefaults removeObjectForKey:kMXKAccountsKey];
[[NSFileManager defaultManager] removeItemAtPath:[self accountFile] error:nil];

[[NSUserDefaults standardUserDefaults] synchronize];
[sharedUserDefaults synchronize];


if (completion)
{
completion();
Expand Down Expand Up @@ -286,7 +283,6 @@ - (NSData *)apnsDeviceToken
if (!token.length)
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"apnsDeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
token = nil;
}
return token;
Expand All @@ -309,7 +305,6 @@ - (void)setApnsDeviceToken:(NSData *)apnsDeviceToken
}

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"apnsDeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand All @@ -320,8 +315,7 @@ - (void)setApnsDeviceToken:(NSData *)apnsDeviceToken
NSLog(@"[MXKAccountManager] set APNS device token");

[[NSUserDefaults standardUserDefaults] setObject:apnsDeviceToken forKey:@"apnsDeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];


// turn on the Apns flag for all accounts, when the Apns registration succeeds for the first time
for (MXKAccount *account in activeAccounts)
{
Expand All @@ -340,8 +334,7 @@ - (void)setApnsDeviceToken:(NSData *)apnsDeviceToken

// Update the token
[[NSUserDefaults standardUserDefaults] setObject:apnsDeviceToken forKey:@"apnsDeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];


// Refresh pushers with the new token.
for (MXKAccount *account in activeAccounts)
{
Expand Down Expand Up @@ -385,7 +378,6 @@ - (NSData *)pushDeviceToken
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"pushDeviceToken"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"pushOptions"];
[[NSUserDefaults standardUserDefaults] synchronize];
token = nil;
}
return token;
Expand Down Expand Up @@ -414,7 +406,6 @@ - (void)setPushDeviceToken:(NSData *)pushDeviceToken withPushOptions:(NSDictiona

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"pushDeviceToken"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"pushOptions"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand All @@ -433,8 +424,7 @@ - (void)setPushDeviceToken:(NSData *)pushDeviceToken withPushOptions:(NSDictiona
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"pushOptions"];
}
[[NSUserDefaults standardUserDefaults] synchronize];


// turn on the Push flag for all accounts
for (MXKAccount *account in activeAccounts)
{
Expand All @@ -461,8 +451,7 @@ - (void)setPushDeviceToken:(NSData *)pushDeviceToken withPushOptions:(NSDictiona
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"pushOptions"];
}
[[NSUserDefaults standardUserDefaults] synchronize];


// Refresh pushers with the new token.
for (MXKAccount *account in activeAccounts)
{
Expand Down Expand Up @@ -540,10 +529,8 @@ - (void)loadAccounts

// Now that data has been migrated, erase old location of accountData
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kMXKAccountsKey];
[[NSUserDefaults standardUserDefaults] synchronize];

[sharedDefaults removeObjectForKey:kMXKAccountsKey];
[sharedDefaults synchronize];
}
}

Expand Down
18 changes: 1 addition & 17 deletions MatrixKit/Models/MXKAppSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ -(instancetype)init
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"sortRoomMembersUsingLastSeenTime"])
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"sortRoomMembersUsingLastSeenTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
sortRoomMembersUsingLastSeenTime = YES;

Expand Down Expand Up @@ -191,9 +190,7 @@ - (void)reset
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"httpsLinkScheme"];

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"enableCallKit"];

[[NSUserDefaults standardUserDefaults] synchronize];
}
}
else
{
syncWithLazyLoadOfRoomMembers = YES;
Expand Down Expand Up @@ -306,7 +303,6 @@ - (void)setShowAllEventsInRoomHistory:(BOOL)boolValue
if (self == [MXKAppSettings standardAppSettings])
{
[[NSUserDefaults standardUserDefaults] setBool:boolValue forKey:@"showAllEventsInRoomHistory"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand Down Expand Up @@ -362,7 +358,6 @@ - (void)setShowRedactionsInRoomHistory:(BOOL)boolValue
if (self == [MXKAppSettings standardAppSettings])
{
[[NSUserDefaults standardUserDefaults] setBool:boolValue forKey:@"showRedactionsInRoomHistory"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand All @@ -387,7 +382,6 @@ - (void)setShowUnsupportedEventsInRoomHistory:(BOOL)boolValue
if (self == [MXKAppSettings standardAppSettings])
{
[[NSUserDefaults standardUserDefaults] setBool:boolValue forKey:@"showUnsupportedEventsInRoomHistory"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand Down Expand Up @@ -416,7 +410,6 @@ - (void)setHttpLinkScheme:(NSString *)stringValue
if (self == [MXKAppSettings standardAppSettings])
{
[[NSUserDefaults standardUserDefaults] setObject:stringValue forKey:@"httpLinkScheme"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand Down Expand Up @@ -445,7 +438,6 @@ - (void)setHttpsLinkScheme:(NSString *)stringValue
if (self == [MXKAppSettings standardAppSettings])
{
[[NSUserDefaults standardUserDefaults] setObject:stringValue forKey:@"httpsLinkScheme"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand All @@ -472,7 +464,6 @@ - (void)setSortRoomMembersUsingLastSeenTime:(BOOL)boolValue
if (self == [MXKAppSettings standardAppSettings])
{
[[NSUserDefaults standardUserDefaults] setBool:boolValue forKey:@"sortRoomMembersUsingLastSeenTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand All @@ -497,7 +488,6 @@ - (void)setShowLeftMembersInRoomMemberList:(BOOL)boolValue
if (self == [MXKAppSettings standardAppSettings])
{
[[NSUserDefaults standardUserDefaults] setBool:boolValue forKey:@"showLeftMembersInRoomMemberList"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand All @@ -524,7 +514,6 @@ - (void)setSyncLocalContacts:(BOOL)boolValue
if (self == [MXKAppSettings standardAppSettings])
{
[[NSUserDefaults standardUserDefaults] setBool:boolValue forKey:@"syncLocalContacts"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand All @@ -549,7 +538,6 @@ - (void)setSyncLocalContactsPermissionRequested:(BOOL)theSyncLocalContactsPermis
if (self == [MXKAppSettings standardAppSettings])
{
[[NSUserDefaults standardUserDefaults] setBool:theSyncLocalContactsPermissionRequested forKey:@"syncLocalContactsPermissionRequested"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand Down Expand Up @@ -592,7 +580,6 @@ - (void)setPhonebookCountryCode:(NSString *)stringValue
if (self == [MXKAppSettings standardAppSettings])
{
[[NSUserDefaults standardUserDefaults] setObject:stringValue forKey:@"phonebookCountryCode"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand Down Expand Up @@ -635,7 +622,6 @@ - (void)setPresenceColorForOnlineUser:(UIColor*)color
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"presenceColorForOnlineUser"];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand Down Expand Up @@ -676,7 +662,6 @@ - (void)setPresenceColorForUnavailableUser:(UIColor*)color
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"presenceColorForUnavailableUser"];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand Down Expand Up @@ -717,7 +702,6 @@ - (void)setPresenceColorForOfflineUser:(UIColor *)color
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"presenceColorForOfflineUser"];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
Expand Down

0 comments on commit 2a57b54

Please sign in to comment.