To The Apples Core
1.0.0

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라는 전체 프로젝트를 만들었습니다. 자세한 정보와 자신의 프로젝트에서 구현하는 방법은 리포지기를 확인하십시오.
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 함수를 사용하려면 __OSX_AVAILABLE_STARTING 매크로를 이러한 함수에 대해 변경해야합니다.
이 작업을 수행하는 가장 쉬운 방법은 Xcode의 함수 이름을 ⌘ + ⌥ + CLICK 해당 헤더로 이동합니다. 여기에서 볼 수 있듯이 매크로를 언급하십시오.
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가 필요 하지 않지만 향후 OS 버전에서 변경 될 수있는 최소 코딩 문자열을 사용합니다.
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 ] )