Capture iOS System Log Messages in Code

I am aware that the new unified logging and tracing system captures system messages which can be analysed within XCode's console. What mechanism can be used to read these messages within code?


In particular, I wish to capture messages denoting when any app on the device moves into, or out of, foreground mode. The general idea is to retrieve and filter messages stored on the device each time the app I'm developing moves into the foreground itself. This information will be used to monitor user activity to determine which apps they've used over a specified period of time.


If it's not possible to use the logging system for this purpose, are you able to propose a mechanism by which this could be achieved?



Thank you

Replies

> I wish to capture messages denoting when any app on the device moves into, or out of, foreground mode. This information will be used to monitor user activity to determine which apps they've used over a specified period of time.


Give it up - your apps only know about themselves. Any 'movement' associated with other apps is private.

What mechanism can be used to read these messages within code?

There is no public API for this.

are you able to propose a mechanism by which this could be achieved?

No. Moreover, if you were able to find such a mechanism I’d consider that to be a serious privacy bug. App A has no business knowing how often I run app B.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for your response eskimo.


Although your privacy concerns are appreciated, the app I am developing is for a research project and the proposed functionality would be used with end-users knowledge and permission.


Does a given app have any way of determining when other apps become active, even if the apps cannot be identified? This wouldn't be as useful, but could help.


In my opinion, it is a shame that the plethora of data produced by the unified logging system can't be used programatically. There are, no doubt, a myriad of commendable uses for these data which would assist end-users and improve their overall experience.


Regards,


CodeInc

the app I am developing is for a research project and the proposed functionality would be used with end-users knowledge and permission.

Cool, but it’s not me you need to convince here. If you think you have a valid use case you should file an enhancement request describing your requirements.

Does a given app have any way of determining when other apps become active, even if the apps cannot be identified?

No.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"