Last active
July 8, 2020 09:40
-
-
Save joaofranco/6862ad802fc5988074315cb9ec7d6319 to your computer and use it in GitHub Desktop.
Springboard Swift 4.1 (based on https://gist.github.com/KoCMoHaBTa/5d2cecfc17db5f3944bc98bcd6fcde55)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Springboard.swift | |
// https://gist.github.com/KoCMoHaBTa/5d2cecfc17db5f3944bc98bcd6fcde55 | |
// | |
// Created by Milen Halachev on 2/15/17. | |
// Copyright © 2017 Milen Halachev. All rights reserved. | |
// | |
import Foundation | |
import XCTest | |
class Springboard { | |
static let shared = Springboard() | |
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") | |
let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences") | |
func deleteApp(withName name: String) { | |
XCUIApplication().terminate() | |
let springboard = self.springboard | |
//springboard.resolve() | |
let icon = springboard.icons[name] | |
if icon.exists { | |
let iconFrame = icon.frame | |
let springboardFrame = springboard.frame | |
//Tap & Hold the app icon in order to go to edit mode | |
Thread.sleep(forTimeInterval: 0.5) | |
icon.press(forDuration: 1.3) | |
//Tap the little "X" button at approximately where it is. The X is not exposed directly | |
Thread.sleep(forTimeInterval: 0.5) | |
springboard.coordinate(withNormalizedOffset: CGVector(dx: (iconFrame.minX + 3) / springboardFrame.maxX, dy: (iconFrame.minY + 3) / springboardFrame.maxY)).tap() | |
//tap the delete alert button | |
Thread.sleep(forTimeInterval: 0.5) | |
springboard.alerts.buttons["Delete"].tap() | |
} | |
//Press home once make the icons stop wiggling | |
Thread.sleep(forTimeInterval: 0.5) | |
XCUIDevice.shared.press(.home) | |
} | |
func resetLocationAndPrivacySettings() { | |
XCUIApplication().terminate() | |
let springboard = self.springboard | |
//springboard.resolve() | |
let settingsIcon = springboard.icons["Settings"] | |
if settingsIcon.exists { | |
//Press home button twise slowly in order to go to the first page of the springboard | |
Thread.sleep(forTimeInterval: 0.5) | |
XCUIDevice.shared.press(.home) | |
//Press home button twise slowly in order to go to the first page of the springboard | |
Thread.sleep(forTimeInterval: 0.5) | |
XCUIDevice.shared.press(.home) | |
//tap the settings icon | |
Thread.sleep(forTimeInterval: 0.5) | |
settingsIcon.tap() | |
let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences") | |
//go to `General` -> `Reset` and tap `Reset Location & Privacy` | |
settings.tables.staticTexts["General"].tap() | |
settings.tables.staticTexts["Reset"].tap() | |
settings.tables.staticTexts["Reset Location & Privacy"].tap() | |
//tap the `Reset Warnings` button | |
Thread.sleep(forTimeInterval: 0.5) | |
settings.buttons["Reset Warnings"].tap() | |
settings.terminate() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment