Skip to content

Commit 1eee9f8

Browse files
authored
Merge pull request ZapicInc#31 from dsarfati/ios-compatibility
iOS Updates
2 parents 17b974f + 945a0d4 commit 1eee9f8

File tree

13 files changed

+35
-32
lines changed

13 files changed

+35
-32
lines changed

Assets/Plugins/iOS/Zapic/Controllers/ZPCPlayerManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#import "ZPCScriptMessageHandler.h"
44

55
@interface ZPCPlayerManager : NSObject
6+
@property (readonly) ZPCPlayer *player;
67
- (instancetype)initWithHandler:(ZPCScriptMessageHandler *)handler;
78
- (void)addLoginHandler:(void (^)(ZPCPlayer *))handler;
89
- (void)addLogoutHandler:(void (^)(ZPCPlayer *))handler;

Assets/Plugins/iOS/Zapic/Controllers/ZPCPlayerManager.m

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#import "ZPCPlayerManager.h"
22

33
@interface ZPCPlayerManager ()
4-
@property ZPCPlayer *player;
54
@property (nonatomic, strong) NSMutableArray<void (^)(ZPCPlayer *)> *loginHandlers;
65
@property (nonatomic, strong) NSMutableArray<void (^)(ZPCPlayer *)> *logoutHandlers;
76
@end

Assets/Plugins/iOS/Zapic/Controllers/Zapic.h

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ extern NSString *const ZPCPageStats;
3939
*/
4040
@property (class, nonatomic, copy, nullable) void (^logoutHandler)(ZPCPlayer *);
4141

42+
/**
43+
Gets the current player. nil if the player is not logged in.
44+
Deprecated in favor of getPlayer:, this will be removed in a future version.
45+
*/
46+
@property (class, nonatomic, copy, nullable, readonly) ZPCPlayer *player DEPRECATED_MSG_ATTRIBUTE("Please use getPlayer:");
47+
4248
#pragma mark - Zapic Methods
4349

4450
/**

Assets/Plugins/iOS/Zapic/Controllers/Zapic.m

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ + (void)initialize {
5555
}
5656
}
5757

58+
+ (ZPCPlayer *)player {
59+
return _core.playerManager.player;
60+
}
61+
5862
#pragma mark - Zapic Methods
5963

6064
+ (void)start {

Assets/Plugins/iOS/Zapic/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.3.0</string>
18+
<string>2.0.0</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

Assets/Plugins/iOS/Zapic/Models/ZPCStatistic.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
*/
1212
@property (nullable, readonly) NSString *title;
1313

14+
/**
15+
The developer defined metadata for this statistic.
16+
*/
17+
@property (nullable, readonly) NSString *metadata;
18+
1419
/**
1520
The current player's score, formatted as defined in the portal.
1621
*/
@@ -26,12 +31,6 @@
2631
*/
2732
@property (nullable, readonly) NSNumber *percentile;
2833

29-
/**
30-
The player's rank on the leaderboard (ex. Top 100). If the player
31-
is not on the leaderboard this value will be nil.
32-
*/
33-
@property (nullable, readonly) NSNumber *rank;
34-
3534
/**
3635
Initialize a new statistic with json data
3736

Assets/Plugins/iOS/Zapic/Models/ZPCStatistic.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ - (instancetype)initWithData:(nonnull NSDictionary *)data {
66
if (self = [super init]) {
77
_identifier = data[@"id"];
88
_title = data[@"title"];
9+
_metadata = data[@"metadata"];
910
_formattedScore = data[@"formattedScore"];
1011
_score = data[@"score"];
11-
_rank = data[@"rank"];
1212
_percentile = data[@"percentile"];
1313
}
1414
return self;

Assets/Plugins/iOS/Zapic/Utilities/ZPCInjectedJS.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ @implementation ZPCInjectedJS
66

77
+ (NSString *)getInjectedScript {
88
//Gets the info to be injected
9-
NSString *sdkVersion = @"1.3.0";
9+
NSString *sdkVersion = @"2.0.0";
1010
NSDictionary *appInfo = NSBundle.mainBundle.infoDictionary;
1111
NSString *appVersion = appInfo[@"CFBundleShortVersionString"];
1212
NSString *appBuild = appInfo[@"CFBundleVersion"];
1313
NSString *bundleId = NSBundle.mainBundle.bundleIdentifier;
1414
NSString *deviceId = UIDevice.currentDevice.identifierForVendor.UUIDString;
1515
NSString *iosVersion = UIDevice.currentDevice.systemVersion;
1616
NSString *installId = [self installId];
17-
const int sdkApiVersion = 3;
17+
const int sdkApiVersion = 4;
1818
const int loadTimeout = 10000;
1919

2020
NSString *adId = @"";

Assets/Plugins/iOS/Zapic/Utilities/ZPCLog.m

-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
@implementation ZPCLog
44

5-
bool isEnabled = true;
6-
75
+ (void)error:(NSString *)message, ... NS_FORMAT_FUNCTION(1, 2) {
86
va_list args;
97
va_start(args, message);
@@ -38,8 +36,6 @@ + (void)info:(NSString *)message, ... NS_FORMAT_FUNCTION(1, 2) {
3836
}
3937

4038
+ (void)writeLog:(NSString *)message withSymbol:(NSString *)symbol {
41-
if (!isEnabled)
42-
return;
4339

4440
NSLog(@"[Zapic][%@]-%@", symbol, message);
4541
}

Assets/Plugins/iOS/Zapic/Utilities/ZPCUtils.h

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
+ (NSString *)toIsoDate:(NSDate *)date;
99
+ (NSDate *)parseDateIso:(NSString *)dateString;
1010
+ (void)cleanDictionary:(NSDictionary *)dict;
11+
+ (int)notchSize;
1112
@end

Assets/Plugins/iOS/Zapic/Utilities/ZPCUtils.m

+9
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,13 @@ + (void)cleanArray:(NSMutableArray *)array {
6969
}
7070
}
7171

72+
+ (int)notchSize {
73+
if (@available(iOS 11.0, *)) {
74+
UIWindow *window = UIApplication.sharedApplication.keyWindow;
75+
return window.safeAreaInsets.top;
76+
} else {
77+
return 0;
78+
}
79+
}
80+
7281
@end

Assets/Plugins/iOS/Zapic/Views/ZPCBanner.m

+2-8
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@ @implementation ZPCBanner
1616

1717
- (instancetype)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle image:(UIImage *)image {
1818
if (self = [super initWithFrame:CGRectZero]) {
19-
int screenHeight = (int)[UIScreen mainScreen].nativeBounds.size.height;
19+
_topPadding = [ZPCUtils notchSize];
2020

21-
//Check if iPhone X
22-
if (screenHeight == 2436) {
23-
if (@available(iOS 11.0, *)) {
24-
UIWindow *window = UIApplication.sharedApplication.keyWindow;
25-
_topPadding = window.safeAreaInsets.top;
26-
}
27-
} else if (![UIApplication sharedApplication].isStatusBarHidden) {
21+
if (![UIApplication sharedApplication].isStatusBarHidden) {
2822
_topPadding = [UIApplication sharedApplication].statusBarFrame.size.height;
2923
}
3024

Assets/Zapic/Plugins/iOS/ZapicInterface.mm

+3-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
BOOL active;
2222
char* start;
2323
char* end;
24-
BOOL hasTotalUsers;
2524
int totalUsers;
2625
int status;
2726
char* formattedScore;
@@ -42,7 +41,6 @@
4241
char* metadata;
4342
char* start;
4443
char* end;
45-
BOOL hasTotalUsers;
4644
int totalUsers;
4745
int status;
4846
char* formattedScore;
@@ -56,13 +54,12 @@
5654
{
5755
char* identifier;
5856
char* title;
57+
char* metadata;
5958
char* formattedScore;
6059
BOOL hasScore;
6160
double score;
62-
BOOL hasRank;
63-
int rank;
6461
BOOL hasPercentile;
65-
float percentile;
62+
int percentile;
6663
} ZPCUStatistic;
6764

6865
typedef struct
@@ -136,7 +133,6 @@ ZPCUCompetition toUnityCompetition(ZPCCompetition *c){
136133
competition.active = c.active;
137134
competition.start = toCString([ZPCUtils toIsoDate:c.start]);
138135
competition.end = toCString([ZPCUtils toIsoDate:c.end]);
139-
competition.hasTotalUsers = hasValue(c.totalUsers);
140136
competition.totalUsers = [c.totalUsers intValue];
141137
competition.status = (int)c.status;
142138
competition.formattedScore = toCString(c.formattedScore);
@@ -158,7 +154,6 @@ ZPCUChallenge toUnityChallenge(ZPCChallenge *c){
158154
challenge.active = c.active;
159155
challenge.start = toCString([ZPCUtils toIsoDate:c.start]);
160156
challenge.end =toCString([ZPCUtils toIsoDate:c.end]);
161-
challenge.hasTotalUsers = hasValue(c.totalUsers);
162157
challenge.totalUsers = [c.totalUsers intValue];
163158
challenge.status = (int)c.status;
164159
challenge.formattedScore = toCString(c.formattedScore);
@@ -173,11 +168,10 @@ ZPCUStatistic toUnityStatistic(ZPCStatistic *c){
173168
ZPCUStatistic statistic;
174169
statistic.identifier = toCString(c.identifier);
175170
statistic.title=toCString(c.title);
171+
statistic.metadata = toCString(c.metadata);
176172
statistic.formattedScore=toCString(c.formattedScore);
177173
statistic.hasScore = hasValue(c.score);
178174
statistic.score = [c.score doubleValue];
179-
statistic.hasRank = hasValue(c.rank);
180-
statistic.rank = [c.rank intValue];
181175
statistic.hasPercentile = hasValue(c.percentile);
182176
statistic.percentile = [c.percentile floatValue];
183177
return statistic;

0 commit comments

Comments
 (0)