Skip to content

Commit

Permalink
feat: update iOS plugin version (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnshi authored Jun 2, 2022
1 parent 5b2890f commit 6d680a7
Show file tree
Hide file tree
Showing 28 changed files with 1,015 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Assets/Amplitude/Amplitude.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class Amplitude {
private static readonly string UnityLibraryName = "amplitude-unity";
private static readonly string UnityLibraryVersion = "2.4.0";
private static readonly string UnityLibraryVersion = "2.5.0";

private static Dictionary<string, Amplitude> instances;
private static readonly object instanceLock = new object();
Expand Down
1 change: 1 addition & 0 deletions Assets/Plugins/iOS/Amplitude/AMPConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ extern NSString *const AMP_TRACKING_OPTION_VERSION_NAME;
extern NSString *const AMP_PLAN_BRANCH;
extern NSString *const AMP_PLAN_SOURCE;
extern NSString *const AMP_PLAN_VERSION;
extern NSString *const AMP_PLAN_VERSION_ID;
3 changes: 2 additions & 1 deletion Assets/Plugins/iOS/Amplitude/AMPConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#import "AMPConstants.h"

NSString *const kAMPLibrary = @"amplitude-ios";
NSString *const kAMPVersion = @"8.5.0"; // Version is managed automatically by semantic-release, please don't change it manually
NSString *const kAMPVersion = @"8.10.0"; // Version is managed automatically by semantic-release, please don't change it manually
NSString *const kAMPUnknownLibrary = @"unknown-library";
NSString *const kAMPUnknownVersion = @"unknown-version";
NSString *const kAMPEventLogDomain = @"api2.amplitude.com";
Expand Down Expand Up @@ -111,3 +111,4 @@
NSString *const AMP_PLAN_BRANCH = @"branch";
NSString *const AMP_PLAN_SOURCE = @"source";
NSString *const AMP_PLAN_VERSION = @"version";
NSString *const AMP_PLAN_VERSION_ID = @"versionId";
13 changes: 10 additions & 3 deletions Assets/Plugins/iOS/Amplitude/AMPDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,17 @@ + (NSString *)generateUUID {
}

+ (NSString *)getPlatformString {
#if !TARGET_OS_OSX
const char *sysctl_name = "hw.machine";
#else
const char *sysctl_name = "hw.model";
#if TARGET_OS_IOS
BOOL isiOSAppOnMac = NO;
if (@available(iOS 14.0, *)) {
isiOSAppOnMac = [NSProcessInfo processInfo].isiOSAppOnMac;
}
if (!isiOSAppOnMac){
sysctl_name = "hw.machine";
}
#elif TARGET_OS_TV || TARGET_OS_WATCH
sysctl_name = "hw.machine";
#endif
size_t size;
sysctlbyname(sysctl_name, NULL, &size, NULL, 0);
Expand Down
60 changes: 60 additions & 0 deletions Assets/Plugins/iOS/Amplitude/AMPMiddleware.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// AMPMiddleware.h
// Copyright (c) 2021 Amplitude Inc. (https://amplitude.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#import <Foundation/Foundation.h>

/**
* AMPMiddlewarePayload
*/
@interface AMPMiddlewarePayload: NSObject

@property NSMutableDictionary *_Nonnull event;
@property NSMutableDictionary *_Nullable extra;

- (instancetype _Nonnull)initWithEvent:(NSMutableDictionary *_Nonnull) event withExtra:(NSMutableDictionary *_Nullable) extra;

@end

/**
* AMPMiddleware
*/
typedef void (^AMPMiddlewareNext)(AMPMiddlewarePayload *_Nullable newPayload);

@protocol AMPMiddleware

- (void)run:(AMPMiddlewarePayload *_Nonnull)payload next:(AMPMiddlewareNext _Nonnull)next;

@end

/**
* AMPBlockMiddleware
*/
typedef void (^AMPMiddlewareBlock)(AMPMiddlewarePayload *_Nonnull payload, AMPMiddlewareNext _Nonnull next);

@interface AMPBlockMiddleware : NSObject <AMPMiddleware>

@property (nonnull, nonatomic, readonly) AMPMiddlewareBlock block;

- (instancetype _Nonnull)initWithBlock:(AMPMiddlewareBlock _Nonnull)block;

@end
33 changes: 33 additions & 0 deletions Assets/Plugins/iOS/Amplitude/AMPMiddleware.h.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions Assets/Plugins/iOS/Amplitude/AMPMiddleware.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// AMPMiddleware.m
// Copyright (c) 2021 Amplitude Inc. (https://amplitude.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#import <Foundation/Foundation.h>
#import "AMPMiddleware.h"

@implementation AMPMiddlewarePayload

- (instancetype _Nonnull)initWithEvent:(NSMutableDictionary *_Nonnull) event withExtra:(NSMutableDictionary *_Nullable) extra {
if ((self = [super init])) {
self.event = event;
self.extra = extra;
}
return self;
}

@end

@implementation AMPBlockMiddleware

- (instancetype _Nonnull)initWithBlock:(AMPMiddlewareBlock)block {
if (self = [super init]) {
_block = block;
}
return self;
}

- (void)run:(AMPMiddlewarePayload *)payload next:(AMPMiddlewareNext)next {
self.block(payload, next);
}

@end
33 changes: 33 additions & 0 deletions Assets/Plugins/iOS/Amplitude/AMPMiddleware.m.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions Assets/Plugins/iOS/Amplitude/AMPMiddlewareRunner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AMPMiddlewareRunner.h
// Copyright (c) 2021 Amplitude Inc. (https://amplitude.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <Foundation/Foundation.h>
#import "AMPMiddleware.h"

@interface AMPMiddlewareRunner : NSObject

@property (nonatomic, nonnull, readonly) NSMutableArray<id<AMPMiddleware>> *middlewares;

+ (instancetype _Nonnull)middleRunner;

- (void) add:(id<AMPMiddleware> _Nonnull)middleware;

- (void) run:(AMPMiddlewarePayload *_Nonnull)payload next:(AMPMiddlewareNext _Nonnull)next;

@end
33 changes: 33 additions & 0 deletions Assets/Plugins/iOS/Amplitude/AMPMiddlewareRunner.h.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions Assets/Plugins/iOS/Amplitude/AMPMiddlewareRunner.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// AMPMiddlewareRunner.m
// Copyright (c) 2021 Amplitude Inc. (https://amplitude.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#import <Foundation/Foundation.h>
#import "AMPMiddlewareRunner.h"
#import "AMPMiddleware.h"

@implementation AMPMiddlewareRunner

- (instancetype)init {
if ((self = [super init])) {
_middlewares = [[NSMutableArray alloc] init];
}
return self;
}

+ (instancetype _Nonnull)middleRunner {
return [[self alloc] init];
}

- (void) add:(id<AMPMiddleware> _Nonnull)middleware {
[self.middlewares addObject:middleware];
}

- (void) run:(AMPMiddlewarePayload *_Nonnull)payload next:(AMPMiddlewareNext _Nonnull)next {
[self runMiddlewares:self.middlewares payload:payload callback:next];
}

- (void) runMiddlewares:(NSArray<id<AMPMiddleware>> *_Nonnull)middlewares
payload:(AMPMiddlewarePayload *_Nonnull)payload
callback:(AMPMiddlewareNext _Nullable)callback {
if (middlewares.count == 0) {
if (callback) {
callback(payload);
}
return;
}

[middlewares[0] run:payload next:^(AMPMiddlewarePayload *_Nullable newPayload) {
NSArray *remainingMiddlewares = [middlewares subarrayWithRange:NSMakeRange(1, middlewares.count - 1)];
[self runMiddlewares:remainingMiddlewares payload:newPayload callback:callback];
}];
}

@end
Loading

0 comments on commit 6d680a7

Please sign in to comment.