Skip to content

Commit e5a3b4e

Browse files
committed
Use app group for shared user defaults, fixes #2
1 parent a3754cf commit e5a3b4e

11 files changed

Lines changed: 141 additions & 64 deletions

File tree

BitStore.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,8 @@
985985
projectRoot = "";
986986
targets = (
987987
03584666194F09A900521709 /* BitStore */,
988-
03AC8C6D199511BE00E901E2 /* BitStore Tests */,
989988
9AAAC41B19D092FD00994EB6 /* BitStoreToday */,
989+
03AC8C6D199511BE00E901E2 /* BitStore Tests */,
990990
);
991991
};
992992
/* End PBXProject section */
@@ -1345,8 +1345,8 @@
13451345
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
13461346
BUNDLE_NAME = com.dylanmarriott.BitStore;
13471347
CODE_SIGN_ENTITLEMENTS = BitStore/BitStore.entitlements;
1348-
CODE_SIGN_IDENTITY = "iPhone Developer: Dylan Marriott (W5F5B94GXS)";
1349-
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Dylan Marriott (W5F5B94GXS)";
1348+
CODE_SIGN_IDENTITY = "iPhone Developer";
1349+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
13501350
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
13511351
GCC_PRECOMPILE_PREFIX_HEADER = YES;
13521352
GCC_PREFIX_HEADER = "BitStore/BitStore-Prefix.pch";
@@ -1371,7 +1371,7 @@
13711371
"$(inherited)",
13721372
);
13731373
PRODUCT_NAME = BitStore;
1374-
PROVISIONING_PROFILE = "bee4a859-9af2-4a1c-a294-fe0bee76faf1";
1374+
PROVISIONING_PROFILE = "";
13751375
WRAPPER_EXTENSION = app;
13761376
};
13771377
name = Debug;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0600"
4+
wasCreatedForAppExtension = "YES"
5+
version = "1.3">
6+
<BuildAction
7+
parallelizeBuildables = "YES"
8+
buildImplicitDependencies = "YES">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "9AAAC41B19D092FD00994EB6"
19+
BuildableName = "BitStoreToday.appex"
20+
BlueprintName = "BitStoreToday"
21+
ReferencedContainer = "container:BitStore.xcodeproj">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
<BuildActionEntry
25+
buildForTesting = "YES"
26+
buildForRunning = "YES"
27+
buildForProfiling = "YES"
28+
buildForArchiving = "YES"
29+
buildForAnalyzing = "YES">
30+
<BuildableReference
31+
BuildableIdentifier = "primary"
32+
BlueprintIdentifier = "03584666194F09A900521709"
33+
BuildableName = "BitStore.app"
34+
BlueprintName = "BitStore"
35+
ReferencedContainer = "container:BitStore.xcodeproj">
36+
</BuildableReference>
37+
</BuildActionEntry>
38+
</BuildActionEntries>
39+
</BuildAction>
40+
<TestAction
41+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
42+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43+
shouldUseLaunchSchemeArgsEnv = "YES"
44+
buildConfiguration = "Debug">
45+
<Testables>
46+
</Testables>
47+
<MacroExpansion>
48+
<BuildableReference
49+
BuildableIdentifier = "primary"
50+
BlueprintIdentifier = "9AAAC41B19D092FD00994EB6"
51+
BuildableName = "BitStoreToday.appex"
52+
BlueprintName = "BitStoreToday"
53+
ReferencedContainer = "container:BitStore.xcodeproj">
54+
</BuildableReference>
55+
</MacroExpansion>
56+
</TestAction>
57+
<LaunchAction
58+
selectedDebuggerIdentifier = ""
59+
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
60+
launchStyle = "0"
61+
askForAppToLaunch = "Yes"
62+
useCustomWorkingDirectory = "NO"
63+
buildConfiguration = "Debug"
64+
ignoresPersistentStateOnLaunch = "NO"
65+
debugDocumentVersioning = "YES"
66+
allowLocationSimulation = "YES">
67+
<BuildableProductRunnable>
68+
<BuildableReference
69+
BuildableIdentifier = "primary"
70+
BlueprintIdentifier = "03584666194F09A900521709"
71+
BuildableName = "BitStore.app"
72+
BlueprintName = "BitStore"
73+
ReferencedContainer = "container:BitStore.xcodeproj">
74+
</BuildableReference>
75+
</BuildableProductRunnable>
76+
<AdditionalOptions>
77+
</AdditionalOptions>
78+
</LaunchAction>
79+
<ProfileAction
80+
shouldUseLaunchSchemeArgsEnv = "YES"
81+
savedToolIdentifier = ""
82+
useCustomWorkingDirectory = "NO"
83+
buildConfiguration = "Release"
84+
debugDocumentVersioning = "YES"
85+
askForAppToLaunch = "Yes">
86+
<BuildableProductRunnable>
87+
<BuildableReference
88+
BuildableIdentifier = "primary"
89+
BlueprintIdentifier = "03584666194F09A900521709"
90+
BuildableName = "BitStore.app"
91+
BlueprintName = "BitStore"
92+
ReferencedContainer = "container:BitStore.xcodeproj">
93+
</BuildableReference>
94+
</BuildableProductRunnable>
95+
</ProfileAction>
96+
<AnalyzeAction
97+
buildConfiguration = "Debug">
98+
</AnalyzeAction>
99+
<ArchiveAction
100+
buildConfiguration = "Release"
101+
revealArchiveInOrganizer = "YES">
102+
</ArchiveAction>
103+
</Scheme>

BitStore/BitStore.entitlements

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
<plist version="1.0">
44
<dict>
55
<key>com.apple.security.application-groups</key>
6-
<array/>
6+
<array>
7+
<string>group.bitstore</string>
8+
</array>
79
<key>keychain-access-groups</key>
810
<array>
911
<string>$(AppIdentifierPrefix)com.dylanmarriott.BitStore</string>

BitStore/Controller/AppStart.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ + (void)setupStorage {
6363
if ([UserDefaults instance].userId == nil) {
6464
[UserDefaults instance].userId = [[NSUUID UUID] UUIDString];
6565
}
66-
67-
if ([UserDefaults instance].sharedUser == nil) {
68-
[UserDefaults instance].sharedUser = [[SharedUser alloc] init];
69-
}
7066
}
7167

7268
+ (void)setupKeychain {

BitStore/Helper/ExchangeHelper.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ - (void)changeCurreny:(NSString *)currency {
5252
_exchange.complete = NO;
5353

5454
// update shared user
55-
SharedUser* user = [UserDefaults instance].sharedUser;
55+
SharedUser* user = [[SharedUser alloc] init];
5656
user.todayCurrency = currency;
5757
user.cachedPrice = nil;
58-
[UserDefaults instance].sharedUser = user;
5958

6059
[self storeState];
6160
[self notifyListeners];

BitStore/Helper/UserDefaults.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
@class Exchange;
1212
@class Address;
1313
@class ContactList;
14-
@class SharedUser;
1514

1615
@interface UserDefaults : NSObject
1716

@@ -29,7 +28,6 @@
2928
@property (nonatomic) BOOL buyShowed;
3029
@property (nonatomic) BOOL buyDismissed;
3130
@property (nonatomic) NSString* customerId;
32-
@property (nonatomic) SharedUser* sharedUser;
3331

3432
+ (UserDefaults *)instance;
3533
- (void)reset;

BitStore/Helper/UserDefaults.m

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#import "Exchange.h"
1111
#import "Address.h"
1212
#import "ContactList.h"
13-
#import "SharedUser.h"
1413

1514
@implementation UserDefaults {
1615
NSUserDefaults* _defaults;
@@ -171,15 +170,6 @@ - (void)setCustomerId:(NSString *)customerId {
171170
[_defaults synchronize];
172171
}
173172

174-
// SharedUser
175-
- (SharedUser *)sharedUser {
176-
return (SharedUser *)[self codableObjectForKey:@"sharedUser"];
177-
}
178-
179-
- (void)setSharedUser:(SharedUser *)sharedUser {
180-
[self setCodableObject:sharedUser forKey:@"sharedUser"];
181-
}
182-
183173
#pragma mark -
184174
- (void)reset {
185175
NSString* domain = [[NSBundle mainBundle] bundleIdentifier];

BitStore/Model/SharedUser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import <Foundation/Foundation.h>
1010

11-
@interface SharedUser : NSObject <NSCoding>
11+
@interface SharedUser : NSObject
1212

1313
@property (nonatomic) NSString* todayCurrency;
1414
@property (nonatomic) NSNumber* cachedPrice;

BitStore/Model/SharedUser.m

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,38 @@
99
#import "SharedUser.h"
1010
#import "UserDefaults.h"
1111

12-
@implementation SharedUser
12+
@implementation SharedUser {
13+
NSUserDefaults* _defaults;
14+
}
1315

1416
- (id)init {
1517
if (self = [super init]) {
16-
self.todayCurrency = @"USD";
18+
_defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.bitstore"];
1719
}
1820
return self;
1921
}
2022

21-
- (id)initWithCoder:(NSCoder *)aDecoder {
22-
if (self = [super init]) {
23-
self.todayCurrency = [aDecoder decodeObjectForKey:@"todayCurrency"];
24-
self.cachedPrice = [aDecoder decodeObjectForKey:@"cachedPrice"];
23+
- (NSString *)todayCurrency {
24+
NSString* ret = [_defaults stringForKey:@"todayCurrency"];
25+
if (!ret) {
26+
ret = @"USD";
27+
[self setTodayCurrency:ret];
2528
}
26-
return self;
29+
return ret;
30+
}
31+
32+
- (void)setTodayCurrency:(NSString *)todayCurrency {
33+
[_defaults setObject:todayCurrency forKey:@"todayCurrency"];
34+
[_defaults synchronize];
2735
}
2836

29-
- (void)encodeWithCoder:(NSCoder *)encoder {
30-
[encoder encodeObject:self.todayCurrency forKey:@"todayCurrency"];
31-
[encoder encodeObject:self.cachedPrice forKey:@"cachedPrice"];
37+
- (NSNumber *)cachedPrice {
38+
return [_defaults objectForKey:@"cachedPrice"];
3239
}
3340

34-
- (NSString *)description {
35-
return [NSString stringWithFormat:@"currency: %@", self.todayCurrency];
41+
- (void)setCachedPrice:(NSNumber *)cachedPrice {
42+
[_defaults setObject:cachedPrice forKey:@"cachedPrice"];
43+
[_defaults synchronize];
3644
}
3745

3846
@end

BitStoreToday/BitStoreToday.entitlements

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<plist version="1.0">
44
<dict>
55
<key>com.apple.security.application-groups</key>
6-
<array/>
6+
<array>
7+
<string>group.bitstore</string>
8+
</array>
79
</dict>
810
</plist>

0 commit comments

Comments
 (0)