Skip to content

Commit

Permalink
New UI and Rename device option (#97)
Browse files Browse the repository at this point in the history
New version 2.1.12
  • Loading branch information
oaliaga authored Oct 17, 2022
1 parent bf4dc66 commit 970dc73
Show file tree
Hide file tree
Showing 36 changed files with 221 additions and 92 deletions.
18 changes: 10 additions & 8 deletions Prey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@
"${PODS_ROOT}/Target Support Files/Pods-Prey/Pods-Prey-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/FirebaseCore/FirebaseCore.framework",
"${BUILT_PRODUCTS_DIR}/FirebaseCoreDiagnostics/FirebaseCoreDiagnostics.framework",
"${BUILT_PRODUCTS_DIR}/FirebaseCoreInternal/FirebaseCoreInternal.framework",
"${BUILT_PRODUCTS_DIR}/FirebaseCrashlytics/FirebaseCrashlytics.framework",
"${BUILT_PRODUCTS_DIR}/FirebaseInstallations/FirebaseInstallations.framework",
"${BUILT_PRODUCTS_DIR}/GoogleDataTransport/GoogleDataTransport.framework",
Expand All @@ -880,6 +881,7 @@
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCore.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCoreDiagnostics.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCoreInternal.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCrashlytics.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseInstallations.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleDataTransport.framework",
Expand Down Expand Up @@ -1230,26 +1232,25 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 36A0DBAF6F614BF750A6DE3F /* Pods-Prey.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_ENTITLEMENTS = Prey/Plist/Prey.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 4;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = M2J57RQ35B;
"EXCLUDED_ARCHS[sdk=*]" = arm64;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = "$(SRCROOT)/Prey/Plist/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = Prey;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 2.1.11;
OTHER_SWIFT_FLAGS = "-D DEBUG";
MARKETING_VERSION = 2.1.12;
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = com.prey;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1266,14 +1267,14 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 635174AA098F25D2F1D8BC05 /* Pods-Prey.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_ENTITLEMENTS = Prey/Plist/Prey.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 4;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = M2J57RQ35B;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "x86_64 i386";
Expand All @@ -1284,7 +1285,8 @@
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 2.1.11;
MARKETING_VERSION = 2.1.12;
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = com.prey;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
6 changes: 6 additions & 0 deletions Prey/Classes/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
PreyNotification.sharedInstance.registerForRemoteNotifications()
TriggerManager.sharedInstance.checkTriggers()
RequestCacheManager.sharedInstance.sendRequest()
DispatchQueue.main.async {
sleep(2)
PreyDevice.infoDevice({(isSuccess: Bool) in
PreyLogger("infoDevice isSuccess:\(isSuccess)")
})
}
} else {
PreyDeployment.sharedInstance.runPreyDeployment()
}
Expand Down
6 changes: 5 additions & 1 deletion Prey/Classes/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import LocalAuthentication

// Storyboard controllerId
enum StoryboardIdVC: String {
case PreyStoryBoard, alert, navigation, home, currentLocation, purchases, settings, grettings, homeWeb
case PreyStoryBoard, alert, navigation, home, currentLocation, purchases, settings, grettings, homeWeb, rename
}

// Def type device
Expand Down Expand Up @@ -150,4 +150,8 @@ enum ReactViews: String {
case REPORTEXAMP = "iosreportexample"
case GOTOSETTING = "iossettingspwd"
case GOTOPANEL = "iospanelpwd"
case GOTORENAME = "iosrenamepwd"
case RENAME = "iosrename"
case NAMEDEVICE = "iosnamedevice"
case INDEX = "iosindex"
}
75 changes: 61 additions & 14 deletions Prey/Classes/HomeWebVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
}

// Check TouchID/FaceID
func checkTouchID(_ openPanelWeb: Bool) {
func checkTouchID(_ openPanelWeb: String?) {

guard PreyConfig.sharedInstance.isTouchIDEnabled == true, PreyConfig.sharedInstance.tokenPanel != nil else {
return
Expand All @@ -112,7 +112,6 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
PreyLogger("error with biometric policy")
return
}
self.showPanel = openPanelWeb
myContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { success, evaluateError in

DispatchQueue.main.async {
Expand All @@ -123,10 +122,14 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
}

// Show webView
if openPanelWeb {
if openPanelWeb == "panel" {
self.goToControlPanel()
} else {
self.goToLocalSettings()
if openPanelWeb == "setting" {
self.goToLocalSettings()
} else {
self.goToRename()
}
}

// Hide credentials webView
Expand Down Expand Up @@ -158,7 +161,7 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
}

// Check password
func checkPassword(_ pwd: String?, view: UIView, openPanelWeb: Bool) {
func checkPassword(_ pwd: String?, view: UIView, back: String) {

// Check password length
guard let pwdInput = pwd else {
Expand Down Expand Up @@ -203,10 +206,14 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
self.sendEventGAnalytics()

// Show webView
if openPanelWeb {
if back == "panel" {
self.goToControlPanel()
} else {
self.goToLocalSettings()
if back == "setting" {
self.goToLocalSettings()
} else {
self.goToRename()
}
}

// Hide credentials webView
Expand Down Expand Up @@ -291,6 +298,17 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
})
})
}

func renameDevice(_ newName: String?){
PreyDevice.renameDevice(newName! ,onCompletion: {(isSuccess: Bool) in
if(isSuccess){
PreyConfig.sharedInstance.nameDevice = newName
PreyConfig.sharedInstance.saveValues()
}
self.loadViewOnWebView("index")
self.webView.reload()
})
}

// Check signUp fields
func checkSignUpFields(_ name: String?, email: String?, password1: String?, password2: String?, term: Bool, age: Bool) {
Expand Down Expand Up @@ -354,7 +372,7 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
}

// Add device action
func addDeviceWithSignUp(_ name: String?, email: String?, password1: String?, password2: String?, term: Bool, age: Bool) {
func addDeviceWithSignUp(_ name: String?, email: String?, password1: String?, password2: String?, term: Bool, age: Bool, offers: Bool?) {

guard let nm = name else {
displayErrorAlert("Name can't be blank".localized,
Expand All @@ -374,7 +392,7 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
actInd.startAnimating()

// SignUp to Panel Prey
PreyUser.signUpToPrey(nm, userEmail:email!, userPassword:pwd1, onCompletion: {(isSuccess: Bool) in
PreyUser.signUpToPrey(nm, userEmail:email!, userPassword:pwd1, offers:offers!, onCompletion: {(isSuccess: Bool) in

// LogIn isn't Success
guard isSuccess else {
Expand Down Expand Up @@ -474,6 +492,11 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
(rootVC as! UINavigationController).pushViewController(resultController, animated: true)
}

func goToRename(){
self.loadViewOnWebView("rename")
self.webView.reload()
}

// MARK: WKUIDelegate

func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
Expand Down Expand Up @@ -581,8 +604,8 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {

case ReactViews.CHECKID.rawValue:
let queryItems = URLComponents(string: reqUrl.absoluteString)?.queryItems
guard let openPanel = queryItems?.filter({$0.name == "openPanelWeb"}).first else {return}
self.checkTouchID(openPanel.value!.boolValue())
let openPanelWeb = queryItems?.filter({$0.name == "openPanelWeb"}).first
self.checkTouchID(openPanelWeb?.value)

case ReactViews.QRCODE.rawValue:
self.addDeviceWithQRCode()
Expand All @@ -593,6 +616,11 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
let pwd = queryItems?.filter({$0.name == "preyPassLogin"}).first
self.addDeviceWithLogin(email?.value, password: pwd?.value)

case ReactViews.RENAME.rawValue:
let queryItems = URLComponents(string: reqUrl.absoluteString)?.queryItems
let newName = queryItems?.filter({$0.name == "newName"}).first
self.renameDevice(newName?.value)

case ReactViews.CHECKSIGNUP.rawValue:
let queryItems = URLComponents(string: reqUrl.absoluteString)?.queryItems
let name = queryItems?.filter({$0.name == "nameSignup"}).first
Expand All @@ -601,6 +629,7 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
let pwd2 = queryItems?.filter({$0.name == "pwd2Signup"}).first
guard let term = queryItems?.filter({$0.name == "termsSignup"}).first else {return}
guard let age = queryItems?.filter({$0.name == "ageSignup"}).first else {return}
let offers = queryItems?.filter({$0.name == "offers"}).first
self.checkSignUpFields(name?.value, email: email?.value, password1: pwd1?.value, password2: pwd2?.value, term: term.value!.boolValue(), age: age.value!.boolValue())

case ReactViews.SIGNUP.rawValue:
Expand All @@ -611,7 +640,8 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
let pwd2 = queryItems?.filter({$0.name == "pwd2Signup"}).first
guard let term = queryItems?.filter({$0.name == "termsSignup"}).first else {return}
guard let age = queryItems?.filter({$0.name == "ageSignup"}).first else {return}
self.addDeviceWithSignUp(name?.value, email: email?.value, password1: pwd1?.value, password2: pwd2?.value, term: term.value!.boolValue(), age: age.value!.boolValue())
let offers = queryItems?.filter({$0.name == "offers"}).first
self.addDeviceWithSignUp(name?.value, email: email?.value, password1: pwd1?.value, password2: pwd2?.value, term: term.value!.boolValue(), age: age.value!.boolValue(), offers: offers?.value?.boolValue() )

case ReactViews.EMAILRESEND.rawValue:
let queryItems = URLComponents(string: reqUrl.absoluteString)?.queryItems
Expand Down Expand Up @@ -664,12 +694,29 @@ class HomeWebVC: UIViewController, WKUIDelegate, WKNavigationDelegate {
case ReactViews.GOTOSETTING.rawValue:
let queryItems = URLComponents(string: reqUrl.absoluteString)?.queryItems
let pwd = queryItems?.filter({$0.name == "pwdLogin"}).first
self.checkPassword(pwd?.value, view: self.view, openPanelWeb: false)
self.checkPassword(pwd?.value, view: self.view, back: "setting")

case ReactViews.GOTOPANEL.rawValue:
let queryItems = URLComponents(string: reqUrl.absoluteString)?.queryItems
let pwd = queryItems?.filter({$0.name == "pwdLogin"}).first
self.checkPassword(pwd?.value, view: self.view, openPanelWeb: true)
self.checkPassword(pwd?.value, view: self.view, back: "panel")

case ReactViews.GOTORENAME.rawValue:
let queryItems = URLComponents(string: reqUrl.absoluteString)?.queryItems
let pwd = queryItems?.filter({$0.name == "pwdLogin"}).first
self.checkPassword(pwd?.value, view: self.view, back: "rename")

case ReactViews.NAMEDEVICE.rawValue:
var nameDevice=PreyConfig.sharedInstance.nameDevice
if nameDevice == nil {
nameDevice="iPhone";
}
self.evaluateJS(self.webView, code: "document.getElementById('nametext').value = '\(nameDevice!)';")
self.evaluateJS(self.webView, code: "var btn = document.getElementById('btnChangeName'); btn.click();")

case ReactViews.INDEX.rawValue:
self.loadViewOnWebView("index")
self.webView.reload()

default:
PreyLogger("Ok")
Expand Down
5 changes: 5 additions & 0 deletions Prey/Classes/PreyConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum PreyConfigDevice: String {
case IsTouchIDEnabled
case ValidationUserEmail
case ExistBackup
case NameDevice
}

enum PreyUserEmailValidation: String {
Expand Down Expand Up @@ -72,6 +73,7 @@ class PreyConfig: NSObject, UIActionSheetDelegate {
reportOptions = defaultConfig.object(forKey: PreyConfigDevice.ReportOptions.rawValue) as? NSDictionary
validationUserEmail = defaultConfig.string(forKey: PreyConfigDevice.ValidationUserEmail.rawValue)
existBackup = defaultConfig.bool(forKey: PreyConfigDevice.ExistBackup.rawValue)
nameDevice = defaultConfig.string(forKey: PreyConfigDevice.NameDevice.rawValue)
}

// MARK: Properties
Expand All @@ -93,6 +95,7 @@ class PreyConfig: NSObject, UIActionSheetDelegate {
var reportOptions : NSDictionary?
var validationUserEmail : String?
var existBackup : Bool
var nameDevice : String?

// MARK: Functions

Expand All @@ -117,6 +120,7 @@ class PreyConfig: NSObject, UIActionSheetDelegate {
defaultConfig.set(reportOptions, forKey:PreyConfigDevice.ReportOptions.rawValue)
defaultConfig.set(validationUserEmail, forKey:PreyConfigDevice.ValidationUserEmail.rawValue)
defaultConfig.set(existBackup, forKey: PreyConfigDevice.ExistBackup.rawValue)
defaultConfig.set(nameDevice, forKey: PreyConfigDevice.NameDevice.rawValue)
}

// Reset values on NSUserDefaults
Expand All @@ -143,6 +147,7 @@ class PreyConfig: NSObject, UIActionSheetDelegate {
needChangeIcon = false
isTouchIDEnabled = true
reportOptions = nil
nameDevice = nil
validationUserEmail = PreyUserEmailValidation.inactive.rawValue
tokenWebTimestamp = 0

Expand Down
27 changes: 26 additions & 1 deletion Prey/Classes/PreyDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,30 @@ class PreyDevice {
displayErrorAlert(alertMsg, titleMessage:titleMsg)
onCompletion(false)
}
}
}

class func renameDevice(_ newName: String, onCompletion:@escaping (_ isSuccess: Bool) -> Void) {

let language:String = Locale.preferredLanguages[0] as String
let languageES = (language as NSString).substring(to: 2)

let params:[String: Any] = [
"name" : newName,
"lang" : languageES]

if let username = PreyConfig.sharedInstance.userApiKey {
PreyHTTPClient.sharedInstance.userRegisterToPrey(username, password:"x", params:params, messageId:nil, httpMethod:Method.PUT.rawValue, endPoint:actionsDeviceEndpoint, onCompletion:PreyHTTPResponse.checkResponse(RequestType.signUp, preyAction:nil, onCompletion:onCompletion))
}else{
PreyLogger("Error renameDevice")
}
}

class func infoDevice(_ onCompletion:@escaping (_ isSuccess: Bool) -> Void) {

if let username = PreyConfig.sharedInstance.userApiKey {
PreyHTTPClient.sharedInstance.userRegisterToPrey(username, password:"x", params:nil, messageId:nil, httpMethod:Method.GET.rawValue, endPoint:infoEndpoint, onCompletion:PreyHTTPResponse.checkResponse(RequestType.infoDevice, preyAction:nil, onCompletion:onCompletion))
}else{
PreyLogger("Error infoDevice")
}
}
}
Loading

0 comments on commit 970dc73

Please sign in to comment.