Skip to content

Commit 07f86eb

Browse files
committed
Added toDictionary methods to classes
* This makes creating wrapper SDKs easier.
1 parent 454b035 commit 07f86eb

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

iOS_SDK/OneSignalSDK/Source/OSPermission.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ - (NSString*)description {
149149
return [NSString stringWithFormat:format, self.hasPrompted, self.statusAsString];
150150
}
151151

152+
- (NSDictionary*)toDictionary {
153+
return @{@"hasPrompted": @(self.hasPrompted),
154+
@"status": @(self.status)};
155+
}
156+
152157
@end
153158

154159

@@ -177,4 +182,9 @@ - (NSString*)description {
177182
static NSString* format = @"<OSSubscriptionStateChanges:\nfrom: %@,\nto: %@\n>";
178183
return [NSString stringWithFormat:format, _from, _to];
179184
}
185+
186+
- (NSDictionary*)toDictionary {
187+
return @{@"from": [_from toDictionary], @"to": [_to toDictionary]};
188+
}
189+
180190
@end

iOS_SDK/OneSignalSDK/Source/OSSubscription.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ - (NSString*)description {
140140
return [NSString stringWithFormat:format, self.userId, self.pushToken, self.userSubscriptionSetting, self.subscribed];
141141
}
142142

143+
- (NSDictionary*)toDictionary {
144+
return @{@"userId": _userId ?: [NSNull null],
145+
@"pushToken": _pushToken ?: [NSNull null],
146+
@"userSubscriptionSetting": @(_userSubscriptionSetting),
147+
@"subscribed": @(self.subscribed)};
148+
}
149+
143150
@end
144151

145152

@@ -168,4 +175,10 @@ - (NSString*)description {
168175
static NSString* format = @"<OSSubscriptionStateChanges:\nfrom: %@,\nto: %@\n>";
169176
return [NSString stringWithFormat:format, _from, _to];
170177
}
178+
179+
- (NSDictionary*)toDictionary {
180+
return @{@"from": [_from toDictionary],
181+
@"to": [_to toDictionary]};
182+
}
183+
171184
@end

iOS_SDK/OneSignalSDK/Source/OneSignal.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,15 @@ typedef NS_ENUM(NSInteger, OSNotificationPermission) {
183183

184184
@property (readonly, nonatomic) BOOL hasPrompted;
185185
@property (readonly, nonatomic) OSNotificationPermission status;
186+
- (NSDictionary*)toDictionary;
186187

187188
@end
188189

189190
@interface OSPermissionStateChanges : NSObject
190191

191192
@property (readonly) OSPermissionState* to;
192193
@property (readonly) OSPermissionState* from;
194+
- (NSDictionary*)toDictionary;
193195

194196
@end
195197

@@ -205,15 +207,16 @@ typedef NS_ENUM(NSInteger, OSNotificationPermission) {
205207
@property (readonly, nonatomic) BOOL userSubscriptionSetting; // returns setSubscription state.
206208
@property (readonly, nonatomic) NSString* userId; // AKA OneSignal PlayerId
207209
@property (readonly, nonatomic) NSString* pushToken; // AKA Apple Device Token
210+
- (NSDictionary*)toDictionary;
208211

209212
@end
210213

211214
@interface OSSubscriptionStateChanges : NSObject
212215

213216
@property (readonly) OSSubscriptionState* to;
214217
@property (readonly) OSSubscriptionState* from;
215-
@property (readonly) BOOL becameSubscribed;
216-
@property (readonly) BOOL becameUnsubscribed;
218+
219+
- (NSDictionary*)toDictionary;
217220

218221
@end
219222

@@ -228,6 +231,7 @@ typedef NS_ENUM(NSInteger, OSNotificationPermission) {
228231

229232
@property (readonly) OSPermissionState* permissionStatus;
230233
@property (readonly) OSSubscriptionState* subscriptionStatus;
234+
- (NSDictionary*)toDictionary;
231235

232236
@end
233237

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@
101101

102102

103103
@implementation OSPermissionSubscriptionState
104+
- (NSString*)description {
105+
static NSString* format = @"<OSPermissionSubscriptionState:\npermissionStatus: %@,\nsubscriptionStatus: %@\n>";
106+
return [NSString stringWithFormat:format, _permissionStatus, _subscriptionStatus];
107+
}
108+
- (NSDictionary*)toDictionary {
109+
return @{@"permissionStatus": [_permissionStatus toDictionary],
110+
@"subscriptionStatus": [_subscriptionStatus toDictionary]};
111+
}
104112
@end
105113

106114
@interface OSPendingCallbacks : NSObject

0 commit comments

Comments
 (0)