How to detect method calls in Objective-C [duplicate] - ios

This question already has answers here:
Track all ObjC method calls?
(5 answers)
Closed 9 years ago.
I'm wondering if there is any way to log all method calls in iOS app? I know that I can add NSLog in every method which call I want to log, but I'm wondering if there is a simpler way? For example some internal mechanism which allow me to hook to all methods calls and fire some method/macro in that case. I simple words, how to catch method call and invoke other method before it? Is it even possible?

If you want to do that only for a couple of classes, then I think you could use the decorator pattern with NSProxy.

There is (albeit quite hidden) support for this already:
Just set an environment variable NSObjcMessageLoggingEnabled to YES
and look in the file: /tmp/msgSends-<processID>
The file should be easy to find if you are using the simulator (I only tested on a Simulator), but may require a jailbroken device to access the output on a device. I'll have a look to see if there is a way to route the output to a user defined file.

Related

iOS Siri add custom vocabulary [duplicate]

This question already has an answer here:
how do i create and use custom vocabulary with sirikit?
(1 answer)
Closed 4 years ago.
I have some troubles to add custom vocabulary to Siri.
I have implemented Siri in my app and it works well with classical commands. However, I tried to add a custom phrase and it doesn't recognized it.
I tried the two ways described in "https://developer.apple.com/library/content/documentation/Intents/Conceptual/SiriIntegrationGuide/SpecifyingCustomVocabulary.html#//apple_ref/doc/uid/TP40016875-CH6-SW1" and followed all the steps.
Do you have any other tips or explanations ? Or could you tell me how I can debug this because I have no clue of what happening, if my AppIntentVocabulary.plist is taken into account or not for exemple.
Answer https://stackoverflow.com/a/48861352/1351327.
A lot of people faced this problem like me in the past.
We should wait Apple to add new intent domains. Open radar has so many requests for that.

Giving or changing the implementation of method at runtime in iOS

Recently i caught with the a thought of changing the implementation of method after deployment
When i googled about objective c runtime and all, came to know about method swizzling methodExchangeImplementations etc.
I know that it could be possible by https://rollout.io/
But my thought is how to do Hot Patching by myself for simple things.
my idea is injecting the code using webservice call.
Webservice should give a replacement for particular method.
That string has to be converted to executable code
What i want to know is ...
How to inject the code in existing method of enterprise application.
For ex:
Consider this method in objective c
-(void)fetchTheResult{
// some code lines
}
After deployment i would like to change the method implementation to
-(void)fetchTheresult{
NSLog(#"test log");
//some Code lines
//some more lines
}
Please guide me the way to achieve this
This is a big question and you've some research to do to figure out an answer. Here as some things you can look into:
First you've referenced Rollout, you could follow the same idea and send your update as JavaScript. You'll need to study how to call JavaScript, swizzle methods, and probably dynamically add methods - more on that in a moment.
An alternative you can investigate is dynamic library loading - you can open, and call code in, a library which your app loads at runtime. So you could look at sending your update as a library. You'll still need to do method swizzling and probably dynamically add methods...
As well as method swizzling you may find you need to dynamically add methods - e.g. so you have something to swap the existing implementation to. A good place to find out how to do that is Mike Ash's writings on KVO - go DuckDuckGo (or Google)
HTH
It is not as easy as you think, at least in Objective C and other similar compiled languages. This kind of runtime changes to the code is only possible in interpreted languages like Javascript.
The basic problem is, the apps are not allowed to change the executable files themselves. The apps on iOS and Android run in a sandboxed environment, and thus have access to limited disk locations only.
Also, after compiling the code, the code does not know where the part of code is converted and stored in machine language. You have to understand the basics of compilers to understand this. There are heavy optimisations happening to your code during this process.

Will I be able to restart my iPhone app programatically to apply language changes in Swift [duplicate]

This question already has answers here:
Force iphone app to restart programmatically?
(7 answers)
Closed 8 years ago.
I am developing an iPhone app in swift and wanted localisation feature inside it.
When the user selects a language in the app, the UI components such as labels/buttons,etc.,. fails to change the language and takes more time in some cases also.
So i needed to manually restart my app when the users want to change the language.
Can anyone please suggest me how to do that.
Thanks in advance.
Swift is a language, not an API. You have the same functionality available to you in Swift as in Objective C, although the syntax and ease of use may differ between the languages.
The answer you linked to therefore already answers the question.
Also, as Hemang points out, don't do this.
It's symptomatic of bad design that you would need to restart the app to change the displayed language.
It would be much better to fix the underlying problem than to apply a hacky band-aid solution such as this.
DONT EVER DO THIS... else you'll surely reject by Apple, I don't know what problem you're facing after user change different language from your app, because I'd worked on this kind of app before (which supports multiple language and user may able to change it while current running of the app). I don't have idea with Swift but in ObjectiveC it works perfect.
From Documentation, https://developer.apple.com/library/ios/qa/qa1561/_index.html
Warning: Do not call the exit function. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen.
NOT RECOMMENDED but still, you can ask user to Restart their app whenever they changed the language with proper message like, " needs to restart to take effect of language change, [please save your any on going work] and close and again open the app to see the effect, thanks !"
Here, the words inside <...> should be your app name, and [...] need to show if you're making an app that needs to save user information before exit?.

Reload AppDelegate Object [duplicate]

This question already has answers here:
Force iphone app to restart programmatically?
(7 answers)
Closed 9 years ago.
I have an appdelegate that contains a lot of objects, which are initialized and
accessed from various places in the App.
I have a view controllers also in the appdelegate, and at some point in the Application, i need all of that to be reinitialized like the app is firstly run. and the appdelegate is firstly initialized.
How can i achieve that?
the [appDelegate finishLoadingWithOptions:nil] didn't work for me, because it doesn't
reinitialize the view controller which i connect using IBOutlet.
Please don't advise me to do it differently, because i am working on
project that is not of my work, and poorly documented.
Sounds like you basically want to totally restart your app. If that's the case, this previous question is going to be your best bet (I'm marking this as a duplicate as well for that reason).
That said, I think it would be well worth spending some time pulling out the data from your app delegate into something more appropriate. The application delegate is certainly convenient for storing data used throughout your app, but it's not really appropriate.
I know you say "please don't advise me to do it differently", but even though it's not your own code you could still re-factor it and make it better. Hopefully you'll be able to!

iOS Jailbroken devices development: How to dump method calls

I am pretty new to development for iOS devices with jailbreak. From what I am reading I understand that to be able to do all the cool things which you can't do on non-jailbroken phones you have to hook up to a given class and override some of its behaviour. Since there is no documentation how a developer tracks to which class exactly he should hook?
I imagine that for instance if I wanted to have my app respond to a given event such as phone boot, call hang up or user clicking on an icon I would manually generate the given event and see what invocations have been made. Is this the proper way to track where you should hook your code and if yes how is it done.
Note I am not interested in exactly those events mentioned above I am more interested the approach in general.
There are several approaches:
Disassemble binaries
You can disassemble a binary or just dump classes with something like class-dump.
So, you can see the whole hierarhy of classes.
Find dumped classes
Most of major iOS subsystems were dissasembled by somebody already. You can find quite a lot of useful stuff.
As example. Google search "Springboard headers" got this
Dump classes in a runtime.
Look at this question for explanation: List selectors for Objective-C object

Resources