CrossClassify iOS SDK
The CrossClassify SDK for iOS apps, with two integrated examples:
- FirebaseSwiftUI: a simple SwiftUI app for login/signup using Firebase Authentication integrated with CrossClassify SDK using Swift Package Manager
- FirebaseUIKit: a simple UIKit app for login/signup using Firebase Authentication integrated with CrossClassify SDK using CocoaPods
See Section Setup Example Apps Locally to run the complete example apps, or navigate to Section SDK Integration Guide to easily integrate CrossClassify SDK with your iOS app.
Prerequisites
- iOS 13.0 (or later)
- Xcode 13.3.1 (or later)
- Swift 5.6 (or later)
- SwiftPM or CocoaPods 1.10.0 (or later)
- SwiftUI or UIKit
- A CrossClassify account
- A Firebase account (only for example apps)
Setup Example Apps locally
- Clone or download the project
- Run the terminal on the project folder
pod installorarch -x86_64 pod install- Open .xcworkspace file
- Copy the
GoogleService-Info.plist(from your Firebase project) file to these paths:- ./Example/FirebaseSwiftUI/FirebaseSwiftUI
- ./Example/FirebaseUIKit/FirebaseUIKit
- Change the
siteIdandapiKey(from your CrossClassify project) in CrossClassify instances placed in:- ./Example/FirebaseSwiftUI/FirebaseSwiftUI/CrossClassifyInstance.swift
- ./Example/FirebaseUIKit/FirebaseUIKit/CrossClassifyInstance.swift
- Build and run (FirebaseSwiftUI or FirebaseUIKit target).
SDK Integration Guide
To make it easy for you to get started with CrossClassify SDK, here's the list of the next steps:
- Install the CrossClassify SDK
- Import the CrossClassify module
- Initialize the CrossClassify object
- Track pages without any form
- Track pages containing a form
Step 1: Install the CrossClassify SDK
-
Swift Package Manager
To integrate via a
Package.swiftmanifest instead of Xcode, you can add CrossClassify to the dependencies array of your package:dependencies: [ .package(url: "https://github.com/crossclassify/xc-sdk-ios", from: "1.0.1"), // Any other dependencies you have... ],
Then, in any target that depends on the CrossClassify SDK, add it to the
dependenciesarray of that target:.target( name: "MyTargetName", dependencies: [ .product(name: "CrossClassify", package: "xc-sdk-ios"), // Any other dependencies you have... ] ),
Or add the package by selecting
File→Add Packages…in Xcode’s menu bar. -
CocoaPods
-
Open a terminal window and navigate to the root directory of your project.
-
If you don't already have a
Podfile, create one by running the following command:pod init -
Open the
Podfilein a text editor and add the following line:pod 'CrossClassify' -
Save the
Podfileand run the following command to install the CrossClassify SDK:pod install
-
Step 2: Import the CrossClassify module
In the file where you want to use the CrossClassify SDK, add the following line at the top:
import CrossClassifyStep 3: Initialize the CrossClassify object
Add the following code to your app, replacing "SITE_ID_HERE" and "API_KEY_HERE" with your site ID and API key:
extension CrossClassify {
public static let shared: CrossClassify = CrossClassify(siteId: "SITE_ID_HERE", apiKey: "API_KEY_HERE")
}This creates a static constant named shared that is an instance of the CrossClassify class initialized with your site ID and API key.
Step 4: Track pages without any form
For each page that contains no form (e.g. home page) do the following instruction. Based on your selected framework, see steps 4.1 and 4.2 for SwiftUI and UIKit versions respectively. In both versions, you must specify the page name.
Step 4.1: SwiftUI pages
- Add the following functions in the
bodyvariable of theviewstruct, repacing the"PAGE_NAME_HERE"with the actual name of the page you want to track:.onAppear{CrossClassify.shared.track(pageName: "PAGE_NAME_HERE")} .onDisappear{CrossClassify.shared.stopTrack()}
Step 4.2: UIKit pages
- Add the following code in the
viewDidAppear(_:), repacing the"PAGE_NAME_HERE"with the actual name of the page you want to track:CrossClassify.shared.track(pageName: "PAGE_NAME_HERE")
- Add the following code in the
viewDidDisappear(_:)method:CrossClassify.shared.stopTrack()
Step 5: Track pages containing a form
For each page that contains a form (e.g. signup, login) do the following instructions. Based on your selected framework, see steps 5.1 and 5.2 for SwiftUI and UIKit versions respectively. In both versions, you must specify the following information:
- The page name (e.g.
loginPage,signupPage, andupdateProfilePage) - The form name (e.g.
login,singup, andupdateProfile) - For each field in the form:
- ID (e.g.
username,password, andaddress) - Content tracking status (whether you want to send us the field content)
Note
Sending field contents increases the accuracy of the CrossClassify fraud detection algorithm. Hence, content tracking is HIGHLY RECOMMENDED on all non-confidential fields.
- ID (e.g.
- The submission button
Step 5.1: SwiftUI pages
-
Specify Page Name and Form Name
Call the following functions from the
bodyvariable of theviewstruct:.onAppear{CrossClassify.shared.track(pageName: "PAGE_NAME_HERE", formName: "FORM_NAME_HERE")} .onDisappear{CrossClassify.shared.stopTrack()}
Replace
"PAGE_NAME_HERE"and"FORM_NAME_HERE"with the actual names of the page and the form you want to track. -
Specify Tracked Form Fields
For a text field (e.g. email), change the
TextFieldstruct toTrackedTextField. Also, you have to specify the id and content tracking status (trackContent):TrackedTextField("AS_IS", // leave this parameter with no change text: $AS_IS), // leave this parameter with no change id: "FIELD_NAME_HERE", trackContent: false, cc: CrossClassify.shared)
If the text field doesn't contain private information (e.g. password), change the second function input to
true. Supported SwiftUI fields in the CrossClassify SDK areTextField,SecureField,DatePicker,Picker,Toggle,Stepper, andSlider. For all field types, simply add theTrackedprefix to the field name (e.g.TrackedStepper) -
Specify the Form Submission Button
Add the following code inside the
actionparameter of the button:CrossClassify.shared.submit()
Step 5.2: UIKit pages
-
Specify Page Name and Form Name
- add the following code in the
viewDidAppear(_:)method if the page contains a form:ReplaceCrossClassify.shared.track(pageName: "PAGE_NAME_HERE", formName: "FORM_NAME_HERE", view: view)
"PAGE_NAME_HERE"and"FORM_NAME_HERE"with the actual name of the page and the form you want to track. - Add the following code in the
viewDidDisappear(_:)method:CrossClassify.shared.stopTrack()
- add the following code in the
-
Specify Tracked Form Fields
-
For a text field (e.g. email), change the
UITextFieldclass toTrackedUITextFieldand its module toCrossClassify. -
In the Attributes Inspector, add a new User Defined Runtime Attribute with Key Path
idand set its value to the id of the text field (e.g.password). Also, if the text field doesn't contain private information (e.g.username), add another boolean attribute with Key PathincludeContent.
With these steps, you have successfully added a TrackedUITextField to your ViewController and set its formName and id attributes. Repeat this process for any additional fields in your form. Supported UIKit fields in the CrossClassify SDK are
UITextField,UIDatePicker,UISegmentedControl,UIPickerView,UISwitch, andUISlider. For all field types, simply add theTrackedprefix to the field name (e.g.TrackedUIDatePicker) -
-
Specify the Form Submission Button
Change the
UIButtonclass toTrackedUIButtonand its module toCrossClassify.
Requirements of Fraud Detection Sevices
Account Opening Service:
- Valid
SiteIdandapiKey(from CrossClassify account) - In the
trackfunction, theformNamemust contain thesignupsubstring (e.g.signupFrom). - In the email field, the
idmust contain theemailsubstring. - In the email field, the
trackContentmust beTrue. - In the signup form view, the form submission button must be specified.
Account Takeover Service:
- Valid
SiteIdandapiKey(from CrossClassify account) - In the
trackfunction, theformNamemust contain theloginsubstring (e.g.loginFrom). - In the email field, the
idmust contain theemailsubstring. - In the email field, the
trackContentmust beTrue. - In the login form view, the form submission button must be specified.
A Simple SwiftUI Example
In this example, we show the changes made in a simple SwiftUI application, before and after applying the integration steps. The CrossClassifyInstance.swift is a new file, and the LoginView.swift is an existing file:
CrossClassifyInstance.swift
+ import CrossClassify
+
+ extension CrossClassify {
+ public static let shared = CrossClassify(siteId: "1", apiKey: "GOTOappDOTcrossclassifyDOTcom")
+ }
SignInView.swift
import SwiftUI
+ import CrossClassify
struct SignInView: View {
@State var emailAddress: String = ""
@State var password: String = ""
var body: some View {
VStack {
- TextField(
+ TrackedTextField(
"[email protected]",
text: $emailAddress),
+ id: "email", trackContent: true, cc: CrossClassify.shared
)
- SecureField(
+ TrackedSecureField(
"Enter a password",
text: $password),
+ id: "password", cc: CrossClassify.shared
)
Button("Sign In", action: {
+ CrossClassify.shared.submit()
...
}
)
...
}
+ .onAppear{CrossClassify.shared.track(pageName: "signin", formName: "login")}
+ .onDisappear{CrossClassify.shared.stopTrack()}
}
}
A Simple UIKit Example
In this example, we show the changes made in a simple UIKit application, before and after applying the integration steps. The CrossClassifyInstance.swift is a new file. Also, LoginViewController.swift and Login.storyboard are existing files:
CrossClassifyInstance.swift
+ import CrossClassify
+
+ extension CrossClassify {
+ public static let shared = CrossClassify(siteId: "1", apiKey: "GOTOappDOTcrossclassifyDOTcom")
+ }
LoginViewController.swift
import UIKit
+ import CrossClassify
class LoginViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
+ CrossClassify.shared.track(pageName: "login", formName: "login", view: view)
...
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
+ CrossClassify.shared.stopTrack()
...
}
}
