Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indoors #370

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIWindowSceneDelegate, UN
print("TrackVerified: status = \(status); token = \(token?.dictionaryValue())")
}
}

demoButton(text: "indoors: trackOnce") {
Radar.trackOnce(desiredAccuracy: .high, beacons: true) { (status, location, events, user) in
print("Track once: status = \(Radar.stringForStatus(status)); location = \(String(describing: location)); events = \(String(describing: events)); user = \(String(describing: user))")
}
}

demoButton(text: "indoors: doIndoorSurvey") {
Radar.doIndoorSurvey("example-app-fake-survey", forLength: 10) { (result) in
print("doIndoorSurvey done")
}
}

demoButton(text: "searchPlaces") {
// In the Radar dashboard settings
Expand Down
53 changes: 29 additions & 24 deletions Example/Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSPinnedDomains</key>
<dict>
<key>api-verified.radar.io</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSPinnedLeafIdentities</key>
<array>
<dict>
<key>SPKI-SHA256-BASE64</key>
<string>15ktYXSSU2llpy7YyCgeqUKDBkjcimK/weUcec960sI=</string>
</dict>
<dict>
<key>SPKI-SHA256-BASE64</key>
<string>15ktYXSSU2llpy7YyCgeqUKDBkjcimK/weUcec960sI=</string>
</dict>
</array>
</dict>
</dict>
</dict>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Please enable Bluetooth for indoors location</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Please enable Bluetooth for indoors location</string>
Comment on lines +47 to +50
Copy link
Contributor

@lmeier lmeier Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: @KennyHuRadar's Info.plist will obviate the need for this

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Your background location usage description goes here.</string>
<key>NSLocationWhenInUseUsageDescription</key>
Expand All @@ -43,6 +71,7 @@
</dict>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>location</string>
</array>
<key>UILaunchStoryboardName</key>
Expand All @@ -66,29 +95,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSPinnedDomains</key>
<dict>
<key>api-verified.radar.io</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSPinnedLeafIdentities</key>
<array>
<dict>
<key>SPKI-SHA256-BASE64</key>
<string>15ktYXSSU2llpy7YyCgeqUKDBkjcimK/weUcec960sI=</string>
</dict>
<dict>
<key>SPKI-SHA256-BASE64</key>
<string>15ktYXSSU2llpy7YyCgeqUKDBkjcimK/weUcec960sI=</string>
</dict>
</array>
</dict>
</dict>
</dict>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Example/Example/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Utils {
return "Exited country \(event.region!.name) (\(event.region!.code)) with \(confidenceStr)"
case .conversion:
return "Received conversion event with name \(event.conversionName!)"
case .indoorLocation:
return "Received indoor location event with .... TODO TODO TODO"
default:
return "Unknown"
}
Expand Down
16 changes: 16 additions & 0 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
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 */; };
50967A182C517B1D00363728 /* RadarIndoorSurvey.m in Sources */ = {isa = PBXBuildFile; fileRef = 50967A142C517B1D00363728 /* RadarIndoorSurvey.m */; };
50967A192C517B1D00363728 /* NSData+GZIP.m in Sources */ = {isa = PBXBuildFile; fileRef = 50967A152C517B1D00363728 /* NSData+GZIP.m */; };
50967A1A2C517B1D00363728 /* NSData+GZIP.h in Headers */ = {isa = PBXBuildFile; fileRef = 50967A162C517B1D00363728 /* NSData+GZIP.h */; };
50967A1B2C517B1D00363728 /* RadarIndoorSurvey.h in Headers */ = {isa = PBXBuildFile; fileRef = 50967A172C517B1D00363728 /* RadarIndoorSurvey.h */; };
532FC304277A790600989279 /* Radar+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 532FC303277A783900989279 /* Radar+Internal.h */; };
53B3B26B23EE41B400080818 /* context.json in Resources */ = {isa = PBXBuildFile; fileRef = 53B3B26A23EE41B400080818 /* context.json */; };
53CCD783275E579800F79CC8 /* RadarLogBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 53CCD782275E579800F79CC8 /* RadarLogBuffer.m */; };
Expand Down Expand Up @@ -185,6 +189,10 @@
01F8106F2AF0119800BD7088 /* RadarVerifiedDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarVerifiedDelegate.h; sourceTree = "<group>"; };
01F99CFA2965C182004E8CF3 /* RadarConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarConfig.h; sourceTree = "<group>"; };
01F99CFC2965C1C4004E8CF3 /* RadarConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RadarConfig.m; sourceTree = "<group>"; };
50967A142C517B1D00363728 /* RadarIndoorSurvey.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarIndoorSurvey.m; sourceTree = "<group>"; };
50967A152C517B1D00363728 /* NSData+GZIP.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+GZIP.m"; sourceTree = "<group>"; };
50967A162C517B1D00363728 /* NSData+GZIP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+GZIP.h"; sourceTree = "<group>"; };
50967A172C517B1D00363728 /* RadarIndoorSurvey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarIndoorSurvey.h; sourceTree = "<group>"; };
532FC303277A783900989279 /* Radar+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Radar+Internal.h"; sourceTree = "<group>"; };
5343FFD923E38BA300808D93 /* RadarContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarContext.m; sourceTree = "<group>"; };
53B3B26A23EE41B400080818 /* context.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = context.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -457,6 +465,10 @@
DD236C772308797B00EB88F9 /* RadarSDK */ = {
isa = PBXGroup;
children = (
50967A162C517B1D00363728 /* NSData+GZIP.h */,
50967A152C517B1D00363728 /* NSData+GZIP.m */,
50967A172C517B1D00363728 /* RadarIndoorSurvey.h */,
50967A142C517B1D00363728 /* RadarIndoorSurvey.m */,
825732502B72BE1900DF8B88 /* PrivacyInfo.xcprivacy */,
96A5A0D827AD9F7F007B960B /* Include */,
DD236C792308797B00EB88F9 /* Info.plist */,
Expand Down Expand Up @@ -639,6 +651,7 @@
01F810702AF0119800BD7088 /* RadarVerifiedDelegate.h in Headers */,
96A5A0CA27AD9F41007B960B /* RadarTrip+Internal.h in Headers */,
96A5A0FF27AD9F7F007B960B /* RadarGeofenceGeometry.h in Headers */,
50967A1A2C517B1D00363728 /* NSData+GZIP.h in Headers */,
96A5A0CB27AD9F41007B960B /* RadarRoute+Internal.h in Headers */,
96A5A10527AD9F7F007B960B /* RadarTrackingOptions.h in Headers */,
96A5A10927AD9F7F007B960B /* RadarContext.h in Headers */,
Expand All @@ -651,6 +664,7 @@
0107AA0F26220047008AB52F /* RadarBeaconManager.h in Headers */,
96A5A0D027AD9F41007B960B /* RadarRouteGeometry+Internal.h in Headers */,
0107AA1626220050008AB52F /* RadarLogger.h in Headers */,
50967A1B2C517B1D00363728 /* RadarIndoorSurvey.h in Headers */,
0107AA1F26220059008AB52F /* RadarSettings.h in Headers */,
96A5A0C027AD9F41007B960B /* RadarRouteDistance+Internal.h in Headers */,
96A5A0D227AD9F41007B960B /* RadarContext+Internal.h in Headers */,
Expand Down Expand Up @@ -839,6 +853,7 @@
0107AB29262201F4008AB52F /* RadarTrackingOptions.m in Sources */,
0107AB2F262201FB008AB52F /* RadarUtils.m in Sources */,
0107AA8926220140008AB52F /* RadarChain.m in Sources */,
50967A192C517B1D00363728 /* NSData+GZIP.m in Sources */,
F667F8272BFBF3C8001F2F67 /* RadarSdkConfiguration.m in Sources */,
F667F8272BFBF3C8001F2F67 /* RadarSdkConfiguration.m in Sources */,
0107AB11262201D9008AB52F /* RadarCollectionAdditions.m in Sources */,
Expand Down Expand Up @@ -868,6 +883,7 @@
01F99CFD2965C1C4004E8CF3 /* RadarConfig.m in Sources */,
0107AB1A262201E2008AB52F /* RadarLogger.m in Sources */,
019514392BD081630031ABA2 /* RadarVerifiedLocationToken.m in Sources */,
50967A182C517B1D00363728 /* RadarIndoorSurvey.m in Sources */,
0107AACE2622018A008AB52F /* RadarRouteDuration.m in Sources */,
0107AB17262201DE008AB52F /* RadarDelegateHolder.m in Sources */,
);
Expand Down
9 changes: 9 additions & 0 deletions RadarSDK/Include/Radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ typedef void (^_Nonnull RadarRouteMatrixCompletionHandler)(RadarStatus status, R
*/
typedef void (^_Nonnull RadarLogConversionCompletionHandler)(RadarStatus status, RadarEvent *_Nullable event);

// define RadarIndoorsSurveyCompletionHandler -- which is called with no arguments
typedef void (^_Nonnull RadarIndoorsSurveyCompletionHandler)(NSString *_Nullable result);

/**
The main class used to interact with the Radar SDK.

Expand Down Expand Up @@ -1086,6 +1089,12 @@ logConversionWithNotification
units:(RadarRouteUnits)units
completionHandler:(RadarRouteMatrixCompletionHandler)completionHandler NS_SWIFT_NAME(getMatrix(origins:destinations:mode:units:completionHandler:));

#pragma mark - Indoors

+ (void)doIndoorSurvey:(NSString *)placeLabel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ (void)doIndoorSurvey:(NSString *)placeLabel
+ (void)surveyIndoors:(NSString *)placeLabel

or something of the like is more in-line with our naming conventions.

forLength:(int)surveyLengthSeconds
completionHandler:(RadarIndoorsSurveyCompletionHandler)completionHandler;

#pragma mark - Logging

/**
Expand Down
1 change: 1 addition & 0 deletions RadarSDK/Include/RadarBeacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ NS_ASSUME_NONNULL_BEGIN

+ (NSArray<NSDictionary *> *_Nullable)arrayForBeacons:(NSArray<RadarBeacon *> *_Nullable)beacons;
- (NSDictionary *_Nonnull)dictionaryValue;
- (void)setRssi:(NSInteger)rssi;

@end

Expand Down
4 changes: 3 additions & 1 deletion RadarSDK/Include/RadarEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ typedef NS_ENUM(NSInteger, RadarEventType) {
/// 'user.arrived_at_wrong_trip_destination`
RadarEventTypeUserArrivedAtWrongTripDestination NS_SWIFT_NAME(userArrivedAtWrongTripDestination),
/// `user.failed_fraud`
RadarEventTypeUserFailedFraud NS_SWIFT_NAME(userFailedFraud)
RadarEventTypeUserFailedFraud NS_SWIFT_NAME(userFailedFraud),
/// `user.indoor_location`
RadarEventTypeIndoorLocation NS_SWIFT_NAME(indoorLocation)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want a new event type here? I think instead we're likely to prefer something like an optional originalLocation on locations

};

/**
Expand Down
2 changes: 2 additions & 0 deletions RadarSDK/Include/RadarTrackingOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ typedef NS_ENUM(NSInteger, RadarTrackingOptionsSyncLocations) {
*/
@property (nonatomic, assign) BOOL beacons;

@property (nonatomic, assign) BOOL indoors;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bigger philosophical naming question: we might want to use the techniques here in contexts that aren't actually indoors (e.g. open air malls, around the covered perimeter of buildings, etc) — would we potentially want to name this something like precise?


/**
Updates about every 30 seconds while moving or stopped. Moderate battery usage. Shows the flashing blue status bar during tracking.
@see https://developer.apple.com/documentation/corelocation/cllocationmanager/2923541-showsbackgroundlocationindicator
Expand Down
43 changes: 43 additions & 0 deletions RadarSDK/NSData+GZIP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// GZIP.h
//
// Version 1.3.2
//
// Created by Nick Lockwood on 03/06/2012.
// Copyright (C) 2012 Charcoal Design
//
// Distributed under the permissive MIT license
// Get the latest version from here:
//
// https://github.com/nicklockwood/GZIP
//
// 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>


@interface NSData (GZIP)

- (nullable NSData *)gzippedDataWithCompressionLevel:(float)level;
- (nullable NSData *)gzippedData;
- (nullable NSData *)gunzippedData;
- (BOOL)isGzippedData;

@end
135 changes: 135 additions & 0 deletions RadarSDK/NSData+GZIP.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//
// GZIP.m
//
// Version 1.3.2
//
// Created by Nick Lockwood on 03/06/2012.
// Copyright (C) 2012 Charcoal Design
//
// Distributed under the permissive MIT license
// Get the latest version from here:
//
// https://github.com/nicklockwood/GZIP
//
// 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 "NSData+GZIP.h"
#import <zlib.h>


#pragma clang diagnostic ignored "-Wcast-qual"


@implementation NSData (GZIP)

- (NSData *)gzippedDataWithCompressionLevel:(float)level
{
if (self.length == 0 || [self isGzippedData])
{
return self;
}

z_stream stream;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
stream.avail_in = (uint)self.length;
stream.next_in = (Bytef *)(void *)self.bytes;
stream.total_out = 0;
stream.avail_out = 0;

static const NSUInteger ChunkSize = 16384;

NSMutableData *output = nil;
int compression = (level < 0.0f)? Z_DEFAULT_COMPRESSION: (int)(roundf(level * 9));
if (deflateInit2(&stream, compression, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY) == Z_OK)
{
output = [NSMutableData dataWithLength:ChunkSize];
while (stream.avail_out == 0)
{
if (stream.total_out >= output.length)
{
output.length += ChunkSize;
}
stream.next_out = (uint8_t *)output.mutableBytes + stream.total_out;
stream.avail_out = (uInt)(output.length - stream.total_out);
deflate(&stream, Z_FINISH);
}
deflateEnd(&stream);
output.length = stream.total_out;
}

return output;
}

- (NSData *)gzippedData
{
return [self gzippedDataWithCompressionLevel:-1.0f];
}

- (NSData *)gunzippedData
{
if (self.length == 0 || ![self isGzippedData])
{
return self;
}

z_stream stream;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.avail_in = (uint)self.length;
stream.next_in = (Bytef *)self.bytes;
stream.total_out = 0;
stream.avail_out = 0;

NSMutableData *output = nil;
if (inflateInit2(&stream, 47) == Z_OK)
{
int status = Z_OK;
output = [NSMutableData dataWithCapacity:self.length * 2];
while (status == Z_OK)
{
if (stream.total_out >= output.length)
{
output.length += self.length / 2;
}
stream.next_out = (uint8_t *)output.mutableBytes + stream.total_out;
stream.avail_out = (uInt)(output.length - stream.total_out);
status = inflate (&stream, Z_SYNC_FLUSH);
}
if (inflateEnd(&stream) == Z_OK)
{
if (status == Z_STREAM_END)
{
output.length = stream.total_out;
}
}
}

return output;
}

- (BOOL)isGzippedData
{
const UInt8 *bytes = (const UInt8 *)self.bytes;
return (self.length >= 2 && bytes[0] == 0x1f && bytes[1] == 0x8b);
}

@end
Loading
Loading