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

add RadarVerifyServer #417

Closed
wants to merge 38 commits into from
Closed

add RadarVerifyServer #417

wants to merge 38 commits into from

Conversation

nickpatrick
Copy link
Contributor

@nickpatrick nickpatrick commented Nov 26, 2024

  • expose startVerifyServer() and stopVerifyServer(), allowing customers to turn their Android app into a "companion app" (https://radar.com/documentation/fraud#web-and-desktop) for trackVerified() and startTrackingVerified() on mobile
  • uses https://github.com/Building42/Telegraph for the server. to make this optional, we use canImport() compiler directive in RadarVerifyServer.swift and a RadarSDK/Verify CocoaPods subspec
  • app and sever are kept alive using location background mode
  • bumps min iOS version to 12 and adds Swift support (already done in other branches)

@nickpatrick nickpatrick mentioned this pull request Nov 26, 2024
@nickpatrick nickpatrick marked this pull request as ready for review November 26, 2024 20:03
@nickpatrick nickpatrick changed the title Companion app 2 add RadarVerifyServer Nov 29, 2024
@@ -23,10 +23,10 @@ jobs:
run: xcodebuild clean build analyze test -workspace Example/Example.xcodeproj/project.xcworkspace -scheme RadarSDK -destination "platform=iOS Simulator,name=iPhone 15 Pro" | xcpretty

- name: Build archive for iPhone simulator (RadarSDK)
run: xcodebuild archive -scheme RadarSDK -archivePath "RadarSDK-iphonesimulator.xcarchive" -sdk iphonesimulator SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
run: xcodebuild archive -scheme RadarSDK -archivePath "RadarSDK-iphonesimulator.xcarchive" -sdk iphonesimulator SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For Swift support

@@ -9,7 +9,7 @@
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<string>5.0</string>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To match SDK Swift version

s.summary = 'iOS SDK for Radar, the leading geofencing and location tracking platform'
s.homepage = 'https://radar.com'
s.author = { 'Radar Labs, Inc.' => 'support@radar.com' }
s.platform = :ios
s.source = { :git => 'https://github.com/radarlabs/radar-sdk-ios.git', :tag => s.version.to_s }
s.source_files = ["RadarSDK/*.{h,m}", "RadarSDK/Internal/*.{h,m}", "RadarSDK/Include/*.h"]
s.source_files = ["RadarSDK/*.{h,m,swift}", "RadarSDK/Include/*.h"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For Swift support

s.module_name = 'RadarSDK'
s.ios.deployment_target = '12.0'
s.frameworks = 'CoreLocation'
s.requires_arc = true
s.license = { :type => 'Apache-2.0' }
s.resource_bundles = {'RadarSDK' => ['RadarSDK/PrivacyInfo.xcprivacy']}
s.swift_version = '5.0'

s.subspec 'Verify' do |ss|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Telegraph dependency added to a subspec, not the main spec

/**
The raw dictionary value of the token.
*/
@property (nullable, copy, nonatomic, readonly) NSDictionary *rawDict;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the server to return the full token response

import Foundation
import UserNotifications

#if canImport(Telegraph)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes Telegraph dependency optional

override init() {
super.init()

locationManager.delegate = self
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used to keep app alive while server is running

response.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS"
}

@objc func startServer(withCertData certData: Data, identityData: Data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Server logic basically matches Mac app


}
#else
@objc(RadarVerifyServer) class RadarVerifyServer: NSObject {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"noop" version if Telegraph dependency not included

@@ -22,6 +22,7 @@ FOUNDATION_EXPORT const unsigned char RadarSDKVersionString[];
#import "RadarEvent.h"
#import "RadarGeofence.h"
#import "RadarGeofenceGeometry.h"
#import "RadarLogger.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to make RadarLogger.h public to use it in Swift

[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeSDKCall message:@"startVerifyServer()"];
[RadarUtils downloadDataFromURL:[NSURL URLWithString:@"https://s3.us-east-2.amazonaws.com/app.radar-verify.com/mac/c.der"] completionHandler:^(NSData * _Nonnull certData, NSError * _Nonnull error) {
[RadarUtils downloadDataFromURL:[NSURL URLWithString:@"https://s3.us-east-2.amazonaws.com/app.radar-verify.com/mac/id.p12"] completionHandler:^(NSData * _Nonnull identityData, NSError * _Nonnull error) {
if (!certData || !identityData) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should be able to do these two downloads at the same time, but it's not that big of a deal since realistically it'll only be called once per session. (not worth the complication)

import Telegraph

@objc(RadarVerifyServer) class RadarVerifyServer: NSObject, CLLocationManagerDelegate {
@MainActor @objc static let sharedInstance = RadarVerifyServer()
Copy link
Contributor

@KennyHuRadar KennyHuRadar Dec 3, 2024

Choose a reason for hiding this comment

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

The modifier @MainActor forces the operations here to be done on the main thread. Is there a specific need for us to do all these non UI tasks on the main thread? This may be especially problematic if the app is running in the background and iOS imposes limitations on the app's main thread utilization (watchdog may decide to crash the app).
I also noticed that we already have semaphores in this implementation as well.


- name: Build archive for iPhone device (RadarSDK)
run: xcodebuild archive -scheme RadarSDK -archivePath "RadarSDK-iphoneos.xcarchive" -sdk iphoneos SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
run: xcodebuild archive -scheme RadarSDK -archivePath "RadarSDK-iphoneos.xcarchive" -sdk iphoneos SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
Copy link
Contributor

Choose a reason for hiding this comment

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

Per our offline discussion, we need to further verify that there are no complications in our SPM distribution which relies on the compiled XCFramework. Happy to assist in the verification process if required :)

@nickpatrick nickpatrick deleted the companion-app-2 branch December 31, 2024 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants