HotReloading: Crashing on injecting to device
App crashes immediately after hitting save. Its a swift project based on UIKit running on a iOS device.
🔥 HotReloading connected /Users/denilct/Documents/Sharechat/HotReload/HotReload.xcodeproj
🔥 Watching files under the directory /Users/denilct/Documents/Sharechat/HotReload
🔥 💉 ⚠️ Your project file seems to be in the Desktop or Documents folder and may prevent InjectionIII working as it has special permissions.
🔥 Compiling /Users/denilct/Documents/Sharechat/HotReload/HotReload/ViewController.swift
🔥 Loaded .dylib - Ignore any duplicate class warning ⬆️
🔥 Interposed 2 function references.
🔥 ⚠️ Number of class refs 2 does not equal []
🔥 Injected type #1 'HotReload.ViewController'
objc[1025]: Attempt to use unknown class 0x109db0340.
import UIKit
class ViewController: UIViewController {
let label = UILabel(frame: CGRect(x: 30, y: 200, width: 200, height: 150))
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
view.addSubview(label)
label.text = "hello"
// Do any additional setup after loading the view.
}
@objc func injected() {
view.backgroundColor = UIColor.yellow
label.text = "anyoooo"
label.backgroundColor = .red
view.layoutIfNeeded()
}
}
Same code works fine for simulator, but crashes on device on hitting save.

About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (11 by maintainers)
It was probably fair enough as a security measure to make a blanket ban on the possibility of code modification on a device after review. The change was made in iOS 10. Device injection works as some other protections are relaxed provided you are debugging an app, see: https://github.com/johnno1962/InjectionScratch/blob/main/Sources/InjectionScratch/InjectionLoader.mm.