Skip to content

Commit

Permalink
Merge pull request #337 from radarlabs/track-verified-callbacks
Browse files Browse the repository at this point in the history
Track verified callbacks
  • Loading branch information
nickpatrick authored Jun 3, 2024
2 parents 3e0afb3 + 953fc6e commit baff0d7
Show file tree
Hide file tree
Showing 23 changed files with 447 additions and 253 deletions.
4 changes: 2 additions & 2 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
self.notify(message)
}

func didUpdateToken(_ token: String) {
func didUpdateToken(_ token: RadarVerifiedLocationToken) {

}

func didUpdateLocationPermissionStatus(status: RadarLocationPermissionStatus){
func didUpdateLocationPermissionStatus(status: RadarLocationPermissionStatus) {

}

Expand Down
39 changes: 34 additions & 5 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
# Migration guides

## 3.12.x to 3.13.x
- The `Radar.trackVerified()` method now returns `token: RadarVerifiedLocationToken`, which includes `user`, `events`, `token,`, `expiresAt`, `expiresIn`, and `passed`. The `Radar.trackVerifiedToken()` method has been removed, since `Radar.trackVerified()` now returns a signed JWT.

```swift
// 3.13.x
Radar.trackVerified { (status, token) in
if token?.passed == true {
// allow access to feature, send token to server for validation
} else {
// deny access to feature, show error message
}
}

// 3.12.x
Radar.trackVerified { (status, location, events, user) in
if user?.fraud?.passed == true &&
user?.country?.allowed == true &&
user?.state?.allowed == true {
// allow access to feature
} else {
// deny access to feature, show error message
}
}

Radar.trackVerifiedToken { (status, token) in
// send token to server for validation
}
```

## 3.11.x to 3.12.x
- `RadarDelegate` interface has been changed to include `didUpdateLocationPermissionStatus` method.
- The `RadarDelegate` interface has been changed to add a `didUpdateLocationPermissionStatus()` method.

## 3.9.x to 3.10.x
- The `searchGeofence` methods have been changed to `Radar.searchGeofences:(completionHandler)` and `Radar.searchGeofences(near:radius:tags:metadata:limit:includeGeometry:completionHandler)`. Use `includeGeometry` to include full geometry of the geofence. Set `radius` to `-1` to search for geofences without a radius limit.
- The `Radar.searchGeofences()` methods have been changed to `Radar.searchGeofences(completionHandler:)` and `Radar.searchGeofences(near:radius:tags:metadata:limit:includeGeometry:completionHandler:)`. Use `includeGeometry` to include full geometry of the geofence. Set `radius` to `-1` to search for geofences without a radius limit.

## 3.8.x to 3.9.0
## 3.8.x to 3.9.x
- The `Radar.autocomplete(query:near:layers:limit:country:expandUnits:completionHandler:)` method is now `Radar.autocomplete(query:near:layers:limit:country:mailable:completionHandler:)`.
- `expandUnits` has been deprecated and will always be true regardless of value passed in.

## 3.6.x to 3.7.0
## 3.6.x to 3.7.x
- Custom events have been renamed to conversions.
- `Radar.sendEvent(customType:metadata:completionHandler:)` is now `Radar.logConversion(name:metadata:completionHandler)`.
- `Radar.logConversion(name:revenue:metadata:callback:)` has been added.
Expand All @@ -20,7 +49,7 @@
- On `RadarEvent`, `customType` is now `conversionName`, and `RadarEventType.custom` is now `RadarEventType.conversion`.

```swift
// 3.7.0
// 3.7.x
let metadata = ["foo": "bar"]

Radar.logConversion(name: "conversion_event", metadata: metadata) { (status, event) in
Expand Down
2 changes: 1 addition & 1 deletion RadarSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'RadarSDK'
s.version = '3.12.0'
s.version = '3.13.0'
s.summary = 'iOS SDK for Radar, the leading geofencing and location tracking platform'
s.homepage = 'https://radar.com'
s.author = { 'Radar Labs, Inc.' => '[email protected]' }
Expand Down
16 changes: 14 additions & 2 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
0114F058284EFDB700ADA4E4 /* RadarRouteMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0114F057284EFDB700ADA4E4 /* RadarRouteMode.h */; settings = {ATTRIBUTES = (Public, ); }; };
015C53AD29B8E8BA004F53A6 /* (null) in Headers */ = {isa = PBXBuildFile; };
015C53AE29B8E8BA004F53A6 /* (null) in Sources */ = {isa = PBXBuildFile; };
019514362BD078D90031ABA2 /* RadarVerifiedLocationToken.h in Headers */ = {isa = PBXBuildFile; fileRef = 019514352BD077D10031ABA2 /* RadarVerifiedLocationToken.h */; settings = {ATTRIBUTES = (Public, ); }; };
019514392BD081630031ABA2 /* RadarVerifiedLocationToken.m in Sources */ = {isa = PBXBuildFile; fileRef = 019514372BD081630031ABA2 /* RadarVerifiedLocationToken.m */; };
0195143A2BD081630031ABA2 /* RadarVerifiedLocationToken+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 019514382BD081630031ABA2 /* RadarVerifiedLocationToken+Internal.h */; };
01F810702AF0119800BD7088 /* RadarVerifiedDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 01F8106F2AF0119800BD7088 /* RadarVerifiedDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
01F99CFB2965C182004E8CF3 /* RadarConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 01F99CFA2965C182004E8CF3 /* RadarConfig.h */; };
01F99CFD2965C1C4004E8CF3 /* RadarConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 01F99CFC2965C1C4004E8CF3 /* RadarConfig.m */; };
Expand Down Expand Up @@ -175,6 +178,9 @@
0107A9E82621FFB9008AB52F /* RadarSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RadarSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; };
0113020E2AE1467800EFC377 /* Network.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Network.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/System/Library/PrivateFrameworks/Network.framework; sourceTree = DEVELOPER_DIR; };
0114F057284EFDB700ADA4E4 /* RadarRouteMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarRouteMode.h; sourceTree = "<group>"; };
019514352BD077D10031ABA2 /* RadarVerifiedLocationToken.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarVerifiedLocationToken.h; sourceTree = "<group>"; };
019514372BD081630031ABA2 /* RadarVerifiedLocationToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarVerifiedLocationToken.m; sourceTree = "<group>"; };
019514382BD081630031ABA2 /* RadarVerifiedLocationToken+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RadarVerifiedLocationToken+Internal.h"; sourceTree = "<group>"; };
01DDC7C529FC387400C0D039 /* RadarNotificationHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarNotificationHelper.m; sourceTree = "<group>"; };
01DDC7C629FC387400C0D039 /* RadarNotificationHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarNotificationHelper.h; sourceTree = "<group>"; };
01F8106F2AF0119800BD7088 /* RadarVerifiedDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarVerifiedDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -398,6 +404,7 @@
96A5A0EE27AD9F7F007B960B /* RadarTripOptions.h */,
96A5A0E027AD9F7F007B960B /* RadarUser.h */,
01F8106F2AF0119800BD7088 /* RadarVerifiedDelegate.h */,
019514352BD077D10031ABA2 /* RadarVerifiedLocationToken.h */,
);
path = Include;
sourceTree = "<group>";
Expand Down Expand Up @@ -577,6 +584,8 @@
DDF1157C2524E18100D575C4 /* RadarTrip.m */,
96A5A0B427AD9F40007B960B /* RadarUser+Internal.h */,
DD236CBB2308812700EB88F9 /* RadarUser.m */,
019514382BD081630031ABA2 /* RadarVerifiedLocationToken+Internal.h */,
019514372BD081630031ABA2 /* RadarVerifiedLocationToken.m */,
);
name = Models;
sourceTree = "<group>";
Expand All @@ -598,6 +607,7 @@
files = (
96A5A0F727AD9F7F007B960B /* RadarEvent.h in Headers */,
96A5A0CD27AD9F41007B960B /* RadarRegion+Internal.h in Headers */,
0195143A2BD081630031ABA2 /* RadarVerifiedLocationToken+Internal.h in Headers */,
96A5A0FD27AD9F7F007B960B /* RadarUser.h in Headers */,
96A5A0C227AD9F41007B960B /* RadarSegment+Internal.h in Headers */,
96A5A0C527AD9F41007B960B /* RadarFraud+Internal.h in Headers */,
Expand All @@ -623,6 +633,7 @@
01F99CFB2965C182004E8CF3 /* RadarConfig.h in Headers */,
96A5A0CF27AD9F41007B960B /* RadarAddress+Internal.h in Headers */,
96A5A11127AD9F7F007B960B /* RadarBeacon.h in Headers */,
019514362BD078D90031ABA2 /* RadarVerifiedLocationToken.h in Headers */,
96A5A10B27AD9F7F007B960B /* RadarTripOptions.h in Headers */,
82F7FAEE2A65FE030055AA4B /* RadarVerificationManager.h in Headers */,
96A5A0C727AD9F41007B960B /* RadarChain+Internal.h in Headers */,
Expand Down Expand Up @@ -859,6 +870,7 @@
96A5A11827ADA02F007B960B /* RadarLog.m in Sources */,
01F99CFD2965C1C4004E8CF3 /* RadarConfig.m in Sources */,
0107AB1A262201E2008AB52F /* RadarLogger.m in Sources */,
019514392BD081630031ABA2 /* RadarVerifiedLocationToken.m in Sources */,
0107AACE2622018A008AB52F /* RadarRouteDuration.m in Sources */,
0107AB17262201DE008AB52F /* RadarDelegateHolder.m in Sources */,
);
Expand Down Expand Up @@ -1013,7 +1025,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = "3.12.0";
MARKETING_VERSION = 3.13.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1071,7 +1083,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = "3.12.0";
MARKETING_VERSION = 3.13.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OTHER_CFLAGS = "-fembed-bitcode";
Expand Down
45 changes: 19 additions & 26 deletions RadarSDK/Include/Radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "RadarRouteMode.h"
#import "RadarRoutes.h"
#import "RadarTrackingOptions.h"
#import "RadarVerifiedLocationToken.h"
#import "RadarUser.h"
#import "RadarLocationPermissionStatus.h"

Expand Down Expand Up @@ -190,13 +191,13 @@ typedef void (^_Nullable RadarTrackCompletionHandler)(RadarStatus status, CLLoca
typedef void (^_Nullable RadarFlushReplaysCompletionHandler)(RadarStatus status, NSDictionary *_Nullable res);

/**
Called when an track request with token callback succeeds, fails, or times out.
Called when a track verified request succeeds, fails, or times out.
Receives the request status and, if successful, a JSON Web Token (JWT) containing an array of the events generated and the user. Verify the JWT server-side using your secret key.
Receives the request status and, if successful, the user's verified location. Verify the token server-side using your secret key.
@see https://radar.com/documentation/sdk/fraud
*/
typedef void (^_Nullable RadarTrackTokenCompletionHandler)(RadarStatus status, NSString *_Nullable token);
typedef void (^_Nullable RadarTrackVerifiedCompletionHandler)(RadarStatus status, RadarVerifiedLocationToken *_Nullable token);

/**
Called when a trip update succeeds, fails, or times out.
Expand Down Expand Up @@ -452,7 +453,7 @@ typedef void (^_Nonnull RadarLogConversionCompletionHandler)(RadarStatus status,
@see https://radar.com/documentation/fraud
*/
+ (void)trackVerifiedWithCompletionHandler:(RadarTrackCompletionHandler _Nullable)completionHandler NS_SWIFT_NAME(trackVerified(completionHandler:));
+ (void)trackVerifiedWithCompletionHandler:(RadarTrackVerifiedCompletionHandler _Nullable)completionHandler NS_SWIFT_NAME(trackVerified(completionHandler:));

/**
Tracks the user's location with device integrity information for location verification use cases.
Expand All @@ -464,41 +465,33 @@ typedef void (^_Nonnull RadarLogConversionCompletionHandler)(RadarStatus status,
@see https://radar.com/documentation/fraud
*/
+ (void)trackVerifiedWithBeacons:(BOOL)beacons completionHandler:(RadarTrackCompletionHandler _Nullable)completionHandler NS_SWIFT_NAME(trackVerified(beacons:completionHandler:));
+ (void)trackVerifiedWithBeacons:(BOOL)beacons completionHandler:(RadarTrackVerifiedCompletionHandler _Nullable)completionHandler NS_SWIFT_NAME(trackVerified(beacons:completionHandler:));

/**
Tracks the user's location with device integrity information for location verification use cases. Returns a JSON Web Token (JWT). Verify the JWT server-side using your secret key.
Starts tracking the user's location with device integrity information for location verification use cases.
@param interval The default interval in seconds between each location update.
@param beacons A boolean indicating whether to range beacons.
@warning Note that you must configure SSL pinning before calling this method.
*/
+ (void)startTrackingVerifiedWithInterval:(NSTimeInterval)interval beacons:(BOOL)beacons NS_SWIFT_NAME(startTrackingVerified(interval:beacons:));

@param completionHandler An optional completion handler.
@see https://radar.com/documentation/fraud
/**
Stops tracking the user's location with device integrity information for location verification use cases.
*/
+ (void)trackVerifiedTokenWithCompletionHandler:(RadarTrackTokenCompletionHandler _Nullable)completionHandler NS_SWIFT_NAME(trackVerifiedToken(completionHandler:));
+ (void)stopTrackingVerified NS_SWIFT_NAME(stopTrackingVerified());

/**
Tracks the user's location with device integrity information for location verification use cases. Returns a JSON Web Token (JWT). Verify the JWT server-side using your secret key.
Returns the user's last verified location token if still valid, or requests a fresh token if not.
@warning Note that you must configure SSL pinning before calling this method.
@param beacons A boolean indicating whether to range beacons.
@param completionHandler An optional completion handler.
@see https://radar.com/documentation/fraud
*/
+ (void)trackVerifiedTokenWithBeacons:(BOOL)beacons completionHandler:(RadarTrackTokenCompletionHandler _Nullable)completionHandler NS_SWIFT_NAME(trackVerifiedToken(beacons:completionHandler:));

/**
Starts tracking the user's location with device integrity information for location verification use cases.
@param token A boolean indicating whether to return a JSON Web Token (JWT). If `true`, tokens are delivered to your `RadarVerifiedDelegate`. If `false`, location updates are delivered to your `RadarDelegate`.
@param beacons A boolean indicating whether to range beacons.
@param interval The interval in seconds between each location update. A number between 1 and 60.
@warning Note that you must configure SSL pinning before calling this method.
*/
+ (void)startTrackingVerified:(BOOL)token interval:(NSTimeInterval)interval beacons:(BOOL)beacons NS_SWIFT_NAME(startTrackingVerified(token:interval:beacons:));
+ (void)getVerifiedLocationToken:(RadarTrackVerifiedCompletionHandler _Nullable)completionHandler NS_SWIFT_NAME(getVerifiedLocationToken(completionHandler:));

/**
Starts tracking the user's location in the background with configurable tracking options.
Expand Down Expand Up @@ -846,7 +839,8 @@ logConversionWithNotification
completionHandler:(RadarSearchPlacesCompletionHandler)completionHandler NS_SWIFT_NAME(searchPlaces(near:radius:chains:chainMetadata:categories:groups:limit:completionHandler:));

/**
Gets the device's current location, then searches for geofences near that location, sorted by distance.
Gets the device's current location, then searches for geofences near that location, sorted by distance.
@param completionHandler A completion handler.
@see https://radar.com/documentation/api#search-geofences
Expand Down Expand Up @@ -874,7 +868,6 @@ Gets the device's current location, then searches for geofences near that locati
includeGeometry:(BOOL)includeGeometry
completionHandler:(RadarSearchGeofencesCompletionHandler)completionHandler NS_SWIFT_NAME(searchGeofences(near:radius:tags:metadata:limit:includeGeometry:completionHandler:));


/**
@deprecated Autocompletes partial addresses and place names, sorted by relevance.
Expand Down
5 changes: 3 additions & 2 deletions RadarSDK/Include/RadarVerifiedDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>

#import "Radar.h"
#import "RadarVerifiedLocationToken.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -19,11 +20,11 @@ NS_ASSUME_NONNULL_BEGIN
@protocol RadarVerifiedDelegate<NSObject>

/**
Tells the delegate that the current user's verified location was updated. Receives a JSON Web Token (JWT). Verify the JWT server-side using your secret key.
Tells the delegate that the current user's verified location was updated. Verify the token server-side using your secret key.
@param token The token.
*/
- (void)didUpdateToken:(NSString *_Nonnull)token NS_SWIFT_NAME(didUpdateToken(_:));
- (void)didUpdateToken:(RadarVerifiedLocationToken *_Nonnull)token NS_SWIFT_NAME(didUpdateToken(_:));

@end

Expand Down
51 changes: 51 additions & 0 deletions RadarSDK/Include/RadarVerifiedLocationToken.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// RadarVerifiedLocationToken.h
// RadarSDK
//
// Copyright © 2024 Radar Labs, Inc. All rights reserved.
//

#import "RadarEvent.h"
#import "RadarUser.h"
#import <Foundation/Foundation.h>

/**
Represents a user's verified location.
@see https://radar.com/documentation/fraud
*/
@interface RadarVerifiedLocationToken : NSObject

/**
The user.
*/
@property (nullable, strong, nonatomic, readonly) RadarUser *user;

/**
An array of events.
*/
@property (nullable, strong, nonatomic, readonly) NSArray<RadarEvent *> *events;

/**
A signed JSON Web Token (JWT) containing the user and array of events. Verify the token server-side using your secret key.
*/
@property (nullable, copy, nonatomic, readonly) NSString *token;

/**
The datetime when the token expires.
*/
@property (nullable, copy, nonatomic, readonly) NSDate *expiresAt;

/**
The number of seconds until the token expires.
*/
@property (assign, nonatomic, readonly) NSTimeInterval expiresIn;

/**
A boolean indicating whether the user passed all jurisdiction and fraud detection checks.
*/
@property (assign, nonatomic, readonly) bool passed;

- (NSDictionary *_Nonnull)dictionaryValue;

@end
8 changes: 8 additions & 0 deletions RadarSDK/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
<string>CA92.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>35F9.1</string>
</array>
</dict>
</array>
</dict>
</plist>
Loading

0 comments on commit baff0d7

Please sign in to comment.