
สำหรับแกนหลักของ Apple ทำหน้าที่เป็นบ้านสำหรับการทดสอบขอบเขตของสิ่งที่สามารถทำได้บน iOS ดั้งเดิมโดยไม่ต้องมีการแหกคุก
โครงการนี้มีวัตถุประสงค์เพื่อการศึกษาและไม่ควรใช้รหัสในแอปพลิเคชันใด ๆ ที่กำหนดเป้าหมายสำหรับ App Store
โครงการและตัวอย่างทั้งหมดถูกสร้างขึ้นและทำงานบนอุปกรณ์ ที่ไม่ใช่เจลเบรค ในขณะที่ยังไม่ผ่านการทดสอบส่วนใหญ่ที่ต่อไปนี้ควรทำงานในสนามเด็กเล่นบน iPad
import Darwin
import Foundation
/**
Obtains an array of dictionaries representing device battery info. Returns nil if there was an issue retrieving info from battery API.
*/
func deviceBatteryInfo ( ) -> [ [ String : AnyObject ] ] ? {
guard case let handle = dlopen ( " /System/Library/PrivateFrameworks/BatteryCenter.framework/BatteryCenter " , RTLD_LAZY ) , handle != nil ,
let c = NSClassFromString ( " BCBatteryDeviceController " ) as AnyObject as? NSObjectProtocol else {
return nil
}
func sharedInstance ( ) -> String { return " sharedInstance " } // Silence compiler warnings
guard c . responds ( to : Selector ( sharedInstance ( ) ) ) == true else { return nil }
let instance = c . perform ( Selector ( sharedInstance ( ) ) ) . takeUnretainedValue ( )
guard let batteries = instance . value ( forKey : " connectedDevices " ) as? [ AnyObject ] else { return nil }
let batteryInfo = batteries . compactMap { battery -> [ String : AnyObject ] ? in
var propertyCount : UInt32 = 0
guard let properties = class_copyPropertyList ( battery . classForCoder , & propertyCount ) else { return nil }
var batteryDictionary = [ String : AnyObject ] ( )
for i in 0 ..< propertyCount {
let cPropertyName = property_getName ( properties [ Int ( i ) ] )
let pName = String ( cString : cPropertyName )
batteryDictionary [ pName ] = battery . value ( forKey : pName ) as AnyObject
}
free ( properties ) //release Obj-C property structs
return batteryDictionary
}
return batteryInfo
}
print ( " Batteries' Info: ( deviceBatteryInfo ( ) ) " ) ![]()
ฉันได้สร้างโครงการทั้งหมดเกี่ยวกับแนวคิดนี้ที่เรียกว่า AppExplorer ตรวจสอบ Repo สำหรับข้อมูลเพิ่มเติมและวิธีที่คุณสามารถนำไปใช้ในโครงการของคุณเอง
class AirplaneManager {
/**
Whether or not airplane mode is enabled. Returns nil if an error occured getting info from API.
*/
static func isAirplaneModeEnabled ( ) -> Bool ? {
guard case let handle = dlopen ( " /System/Library/PrivateFrameworks/AppSupport.framework/AppSupport " , RTLD_LAZY ) , handle != nil ,
let c = NSClassFromString ( " RadiosPreferences " ) as? NSObject . Type else {
return nil
}
let radioPreferences = c . init ( )
if radioPreferences . responds ( to : NSSelectorFromString ( " airplaneMode " ) ) {
return ( radioPreferences . value ( forKey : " airplaneMode " ) as AnyObject ) . boolValue
}
return false
}
}
print ( " Airplane Mode Enabled: ( AirplaneManager . isAirplaneModeEnabled ( ) ) " ) เพื่อที่จะใช้ scdynamicstorecreate และ scdynamicstorecopyvalue ฟังก์ชั่น macro __OSX_AVAILABLE_STARTING จะต้องมีการเปลี่ยนแปลงสำหรับฟังก์ชั่นเหล่านี้
วิธีที่ง่ายที่สุดในการทำเช่นนี้คือ ⌘ + ⌥ + CLICK ที่ชื่อฟังก์ชั่นใน XCode ซึ่งจะนำคุณไปยังส่วนหัวที่เกี่ยวข้อง แสดงความคิดเห็นมาโครตามที่เห็นที่นี่:
SCDynamicStoreRef __nullable SCDynamicStoreCreate (
CFAllocatorRef __nullable allocator,
CFStringRef name,
SCDynamicStoreCallBack __nullable callout,
SCDynamicStoreContext * __nullable context
) /* __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA) */ ; CFPropertyListRef __nullable SCDynamicStoreCopyValue (
SCDynamicStoreRef __nullable store,
CFStringRef key
) /* __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA) */ ;
let reader = MobileHotspotReader . sharedReader
print ( " Connected Devices: ( reader . numberOfConnectedDevices ) " )
print ( " Connected over Bluetooth: ( reader . connectionsOverBluetooth ) " ) รหัสนี้ ไม่ จำเป็นต้องใช้ API ส่วนตัว แต่ใช้สตริงที่ใช้รหัสฮาร์ดซึ่งอาจเปลี่ยนแปลงในเวอร์ชันระบบปฏิบัติการในอนาคต
print ( " Wifi is Enabled : ( NetworkManager . wifiEnabled ( ) ) " )
print ( " Wifi is Connected : ( NetworkManager . wifiConnected ( ) ) " )
print ( " Currently Tethering : ( NetworkManager . isTethering ( ) ) " ) import Darwin
import UIKit
struct WallpaperLocation : OptionSet {
let rawValue : Int
static let lockscreen = WallpaperLocation ( rawValue : 1 << 0 )
static let homescreen = WallpaperLocation ( rawValue : 1 << 1 )
}
func setWallpaper ( image : UIImage , location : WallpaperLocation ) -> Bool {
guard case let handle = dlopen ( " /System/Library/PrivateFrameworks/SpringBoardUI.framework/SpringBoardUI " , RTLD_LAZY ) , handle != nil else {
return false
}
guard case let symbol = dlsym ( handle , " SBSUIWallpaperSetImageAsWallpaperForLocations " ) , symbol != nil else {
return false
}
typealias methodSignature = @ convention ( c ) ( AnyObject , NSInteger ) -> ( )
let _ = unsafeBitCast ( symbol , to : methodSignature . self ) ( image , location . rawValue )
dlclose ( handle )
return true
}
setWallpaper ( image , location : [ . homescreen , . lockscreen ] )