johnno1962 / InjectionIII

Re-write of Injection for Xcode in (mostly) Swift
MIT License
4.07k stars 319 forks source link

The injectionIII doesn't work #128

Closed MIyulong closed 4 years ago

MIyulong commented 5 years ago

when i use command + s, the function of "@objc func injected()" doesn't be called, the terminal log is

πŸ’‰ *** Compiling /Users/yulong/Desktop/chatail-resource/App-ios/Chatail/Features/Share/View/SharePosterViewController.swift ***
πŸ’‰ Loading .dylib ...
objc[38487]: Class _TtC7Chatail25SharePosterViewController is implemented in both /Users/yulong/Library/Developer/CoreSimulator/Devices/D1445DA8-E71C-43D2-B7F6-0DB6044BF0F4/data/Containers/Bundle/Application/318AEF0B-F4FB-4530-9AC6-2F6EB25F1DDF/ζ΄½ζ·˜ε†…ζ΅‹.app/ζ΄½ζ·˜ε†…ζ΅‹ (0x10f6de560) and /Users/yulong/Library/Containers/com.johnholdsworth.InjectionIII/Data/eval103.dylib (0x147fc8280). One of the two will be used. Which one is undefined.
πŸ’‰ Loaded .dylib - Ignore any duplicate class warning ^

and i use version 10.1 xcode and version 1.51 injectionIII, in AppDelegate.swift, i add this Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection10.bundle")?.load()

johnno1962 commented 5 years ago

Hi, Is SharePosterViewController on the screen?

MIyulong commented 5 years ago

Yes. When i press commandοΌ‹s, this controller on the screen

发θ‡ͺζˆ‘ηš„ iPhone

在 2019εΉ΄4月9ζ—₯,22:45,John Holdsworth notifications@github.com ε†™ι“οΌš

Hi, Is SharePosterViewController on the screen?

β€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

zhangferry commented 5 years ago

I had the same problem. Injection connected but doesn't call @objc func injected().

with Xcode10.1 + InjectionIII 1.5.1

πŸ’‰ Injection connected, watching /Users/zhangferry/Desktop/MiniHabit/**
πŸ’‰ *** Compiling /Users/zhangferry/Desktop/MiniHabit/MiniHabit/Scene/HomePage/HomePageViewController.swift ***
πŸ’‰ Loading .dylib ...
objc[12468]: Class _TtC9MiniHabit22HomePageViewController is implemented in both /Users/zhangferry/Library/Developer/CoreSimulator/Devices/0977D680-9A84-4E93-A44A-8183597538B0/data/Containers/Bundle/Application/D45D7DF2-34B9-4E2D-8E2A-66B633EAECD5/MiniHabit.app/MiniHabit (0x100543ee8) and /Users/zhangferry/Library/Containers/com.johnholdsworth.InjectionIII/Data/eval101.dylib (0x12574caf0). One of the two will be used. Which one is undefined.
πŸ’‰ Loaded .dylib - Ignore any duplicate class warning ^
πŸ’‰ Injected 'HomePageViewController'

supplement:

When I use INJECTION_BUNDLE_NOTIFICATION, it take effect only first time. Then I click Ctrl + s, notification function would called but the modification of UI couldn't take effect.

n13 commented 5 years ago

Notification - always calls the old class reliably, so no new code is actually injected. The old class just runs over and over again. I tested this by changing the print statement inside the notification - never changed.

Function @objc func injected() - this gets called every now and then, but not on every save.

    @objc func injected() {
        print("RELOAD2-2-3-4-5")
        self.reloadView()
    }
πŸ’‰ *** Compiling /Users/nik/work/omplanet/omplanet-ios/OMPlanet/OMPlanet/ViewControllers/Auth/EditUserBasicViewController.swift ***
πŸ’‰ Loading .dylib ...
objc[47069]: Class _TtC8OMPlanet27EditUserBasicViewController is implemented in both /Users/nik/Library/Developer/CoreSimulator/Devices/2B4E1973-EB1B-4642-97CE-784AAFE3A13E/data/Containers/Bundle/Application/86103459-41FB-4104-931C-24F0908DF9B7/OMPlanet.app/OMPlanet (0x10be49058) and /Users/nik/Library/Containers/com.johnholdsworth.InjectionIII/Data/eval101.dylib (0x12fd3b950). One of the two will be used. Which one is undefined.
πŸ’‰ Loaded .dylib - Ignore any duplicate class warning ^
πŸ’‰ Injected 'EditUserBasicViewController'
VIEW INIT
setup user
RELOAD2-2-3-4
VIEW INIT
setup user
πŸ’‰ *** Compiling /Users/nik/work/omplanet/omplanet-ios/OMPlanet/OMPlanet/ViewControllers/Auth/EditUserBasicViewController.swift ***
πŸ’‰ Loading .dylib ...
πŸ’‰ Loaded .dylib - Ignore any duplicate class warning ^
πŸ’‰ Injected 'EditUserBasicViewController'
πŸ’‰ *** Compiling /Users/nik/work/omplanet/omplanet-ios/OMPlanet/OMPlanet/ViewControllers/Auth/EditUserBasicViewController.swift ***
πŸ’‰ Loading .dylib ...
objc[47069]: Class _TtC8OMPlanet27EditUserBasicViewController is implemented in both /Users/nik/Library/Developer/CoreSimulator/Devices/2B4E1973-EB1B-4642-97CE-784AAFE3A13E/data/Containers/Bundle/Application/86103459-41FB-4104-931C-24F0908DF9B7/OMPlanet.app/OMPlanet (0x10be49058) and /Users/nik/Library/Containers/com.johnholdsworth.InjectionIII/Data/eval102.dylib (0x12fe1e950). One of the two will be used. Which one is undefined.
πŸ’‰ Loaded .dylib - Ignore any duplicate class warning ^
πŸ’‰ Injected 'EditUserBasicViewController'
πŸ’‰ *** Compiling /Users/nik/work/omplanet/omplanet-ios/OMPlanet/OMPlanet/ViewControllers/Auth/EditUserBasicViewController.swift ***
πŸ’‰ Loading .dylib ...
objc[47069]: Class _TtC8OMPlanet27EditUserBasicViewController is implemented in both /Users/nik/Library/Developer/CoreSimulator/Devices/2B4E1973-EB1B-4642-97CE-784AAFE3A13E/data/Containers/Bundle/Application/86103459-41FB-4104-931C-24F0908DF9B7/OMPlanet.app/OMPlanet (0x10be49058) and /Users/nik/Library/Containers/com.johnholdsworth.InjectionIII/Data/eval103.dylib (0x12fe45950). One of the two will be used. Which one is undefined.
πŸ’‰ Loaded .dylib - Ignore any duplicate class warning ^
πŸ’‰ Injected 'EditUserBasicViewController'
πŸ’‰ *** Compiling /Users/nik/work/omplanet/omplanet-ios/OMPlanet/OMPlanet/ViewControllers/Auth/EditUserBasicViewController.swift ***
πŸ’‰ Loading .dylib ...
objc[47069]: Class _TtC8OMPlanet27EditUserBasicViewController is implemented in both /Users/nik/Library/Developer/CoreSimulator/Devices/2B4E1973-EB1B-4642-97CE-784AAFE3A13E/data/Containers/Bundle/Application/86103459-41FB-4104-931C-24F0908DF9B7/OMPlanet.app/OMPlanet (0x10be49058) and /Users/nik/Library/Containers/com.johnholdsworth.InjectionIII/Data/eval104.dylib (0x12fe6c950). One of the two will be used. Which one is undefined.
πŸ’‰ Loaded .dylib - Ignore any duplicate class warning ^
πŸ’‰ Injected 'EditUserBasicViewController'
πŸ’‰ *** Compiling /Users/nik/work/omplanet/omplanet-ios/OMPlanet/OMPlanet/ViewControllers/Auth/EditUserBasicViewController.swift ***
πŸ’‰ Loading .dylib ...
πŸ’‰ Loaded .dylib - Ignore any duplicate class warning ^
πŸ’‰ Injected 'EditUserBasicViewController'
VIEW INIT
setup user
RELOAD2-2-3-4-5
VIEW INIT
setup user

Note how I am reloading about 5 times before the change from print 1-2-3-4 to print 1-2-3-4-5 happens - in fact until the injection method is even called.

moshiwu commented 5 years ago

same problem but finally success after changing below option Build Setting -> Enable Testability -> YES @johnno1962 This may help to fix some bugs.

gtennis commented 4 years ago

As the issue is still open, I will share what has helped me because I've also stumbled upon a similar issue @n13 had.

My setup: AppCode 2020.1.5, Simulator iOS 13.6, Swift 5, Injection III (2.2.0) from App Store.

I was seeing very similar log entries as @n13 and then I've decided to check the issue on some other empty view controller in the app by changing its background color and it was actually working. Thus I've returned to my view controller I wasn't able to see the changes loaded and started to strip off all the code until it became empty as the previous view controller. Then I ran the app in the simulator and started to change this empty view controller BUT then I saw the following log entry in the console:

πŸ’‰ Injection connected πŸ‘ πŸ’‰ Have you remembered to add "-Xlinker -interposable" to your project's "Other Linker Flags"? πŸ’‰ Watching /Users/some-user/repos/my-awesome-project/**

Once I've added the mentioned flag for DEBUG configuration and put my whole code back to the initial view controller, all started to work.

gtennis commented 4 years ago

Although, if you might not be able to run your app on the real iPhone if bitcode compilation is enabled and thus an error will be shown

-interposable and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together

Removing the flag has helped to run on a device but then we are back to the same issue. However, now I can use injection and apply this workaround :)

johnno1962 commented 4 years ago

Thanks for letting us know @gtennis, that’s good to hear. You should find the new version much more reliable for Swift code.

johnno1962 commented 4 years ago

Just seen your second post. Try something like this:

image
gtennis commented 4 years ago

Great, thanks!

Gytenis

On Mon, Jul 20, 2020 at 11:29 PM John Holdsworth notifications@github.com wrote:

Just seen your second post. Try something like this: [image: image] https://user-images.githubusercontent.com/1786033/87988527-c41de500-cae0-11ea-97e3-5aaa5d09b503.png

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/johnno1962/InjectionIII/issues/128#issuecomment-661343221, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKWB7OCCDTTP6RXWTUAWMDR4SZKZANCNFSM4HERELJA .

JianboYan commented 4 years ago

@MIyulong Do you reload you ViewController? I "have" the same issue before, and then I realized change the UILabel.text or other similar action dose not reload the ViewController automatically (only if you do it yourself when received INJECTION_BUNDLE_NOTIFICATION Notification).