How do I access logs from the past day with os_log from Apple Watch? - watchos

I'm trying to troubleshoot an issue on watchOS.
I'm not sure how to reproduce the problem I'm seeing, but I do encounter it occasionally during testing on a real device in the wild, so I'm trying to use os_log in order to diagnose the problem after the fact.
As a first step, to make sure I understand how how to write to the log and access it later, I've attempted to log an event any time the app first loads.
In the ExtensionDelegate.swift file for my app, I added this:
import os.log
extension OSLog {
private static var subsystem = Bundle.main.bundleIdentifier!
static let health = OSLog(subsystem: subsystem,
category: "health")
}
Then, I updated the applicationDidBecomeActive delegate function with this:
func applicationDidBecomeActive() {
os_log("App Started",
log: OSLog.health,
type: .error)
}
I know it's not really an error message, but from what I've read, messages that are not .error are not written to saved to the log for later. I want to make sure it gets written to the log like a real error would.
I installed the sysdiagnose profile, then installed the the most recent version of my app.
After testing the app for the day, I attempted to export the file. Following the instructions I've found elsewhere, I produced a sysdiagnose on Apple Watch by holding the Digital Crown and Side button for two seconds (and felt the haptic feedback when I released).
Then, I put the watch on the charger for a few minutes per the instructions here, which recommended 15 minutes.
I opened the Watch app on my paired iPhone, then went to General > Diagnostic Logs and downloaded the sysdiagnose from Apple Watch, and sent it to my computer with AirDrop.
This gave me a tarball file (for example, sysdiagnose_2021.03.05_17-01-57-0700_Watch-OS_Watch_18S801.tar.gz). Once I decompressed that, I had a folder of lots of files and subfolders.
After poking around in this folder, I figured my best bet was to look in the system_logs.logarchive file. I opened that in the macOS Console app, set the Showing dropdown to All Messages, and looked around the time I opened the app. I didn't see any log output from my app.
I also filtered for "App Started" (the log message from my app) and didn't find anything.
Then, I filtered by category for "health" and didn't find the event I had logged.
Is system_logs.logarchive the correct place to be looking for the log output from my app?
If not, where should I be looking? Or what am I doing wrong?
I really want a better understanding of how I can log messages on Apple Watch so I can view them later so I can make my Apple Watch apps more robust, but I'm at a dead end.
Am I looking in the wrong place? Or am I setting up the logging wrong? Or is it something else? I would appreciate any guidance about this!

According to the Apple Dev Forms, sysdiagnose allows you to view the logs on your apple watch.

Related

Requesting runtime permissions in Kotlin

I have a MVVM app, which needs Bluetooth through the entire app. The only screen that doesn't require Bluetooth is the Onboarding screen. In the first screen, the app starts automatically searching for devices, which requires BLUETOOTH_SCAN to function properly. I have attempted numerous things to request the runtime permissions and check if the Bluetooth is on, but nothing seemed to work. I'd greatly appreciate any help.
I have tried calling the functions in the onResume() of the activity, but it slows down the app a significant lot. I have also tried requesting the permissions when the startScan() function gets called, but that seems to crash, because in order to start the scan I need to have the permissions allowed and the bluetooth adapter should be initialized, a.k.a Bluetooth should be turned on
Did you had a look at this Answer?
https://stackoverflow.com/a/69972855/20356055
It describes very good how to request the bluetooth permissions.
And don't forget to add the permissions in the manifest ;)

Offline notification with nuxt/pwa

I am currently looking through the options of creating an offline indication for the nuxt/pwa project. Since this moment, app is running perfectly offline, but what I want to do is to push a small notification when there is no connection saying something simple such as "you are currently offline".
I can see that there are multiple ways of doing this such as writing the event listener directly in the default layout, but my question is which one is the most suitable and reliable for the nuxt setup.
I think you don't need to write your own event listener, as this seems to be taken care of by the nuxt already. The network status seems to be accessible via $nuxt helper's isOnline and isOffline properties. Check out this example:
https://nuxtjs.org/api/$nuxt/
I have not worked with this yet, but I think it might be what you are looking for.
Note: Make sure to copy the whole link, as stackoverflow cuts it off at /$nuxt.

Handling iOS 8's Changes To App Containers within Xamarin (alternative to Environment.GetFolderPath)

Per the thread started at (http://forums.xamarin.com/discussion/24860/documents-directory-has-moved-in-ios-8#latest), we are working to adapt our App to the recent changes make in iOS regarding accessing the iOS 8 file structure. We have reviewed and attempted the implementation of the code found within the iOS 8 Note at http://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system/#Creating_Files_and_Directories, and while the results of the sample code does provide some environment
variables, some additional instructions and how to get the results to behave in the same manner as Environment.GetFolderPath would be helpful – or guidance on whatever the appropriate approach should be.
The following takes place after a Release archive is built and pushed to an iPad device running iOS 8.0 (note not 8.0.1). We are using the following code:
var documents = NSFileManager.DefaultManager.GetUrls
(NSSearchPathDirectory.LibraryDirectory,
NSSearchPathDomain.User)
[0].Path
And we get:
/var/mobile/Containers/Data/Application/8C4D70BC-7607-xxxx-xxxx-A503A061E1EF/Library
But when we try to write to files in this directory, we get the following error in the device log:
Sep 25 12:47:22 Cognilores-iPad kernel[0] <Notice>: Sandbox: SEXI_reader(1243) deny file-write-create /usr/share/CogniLore
Is anyone able to help us identify what is going wrong and what workaround we can use? This is a severe issue – our App crashes immediately after users upgrade to 8.0, and we need to get an updated version into the approval process as soon as possible.
Is anyone able to help us identify what is going wrong
The path you show does not match the path from the device logs. Are you sure they come from the same code ?
e.g. maybe another part of your application later try to access a different directory (and this is what you're seeing in the logs) ?
Some quick test shows that the code (below) works fine on iOS8 devices.
var urls = NSFileManager.DefaultManager.GetUrls (NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.User);
var path = urls [0].Path;
File.WriteAllText (Path.Combine (path, "myfile.txt"), "woohoo");

NSTask subprocess stuck in _dyld_start

I use NSTask to run my helper application. On 99% one my customer systems this works fine, but two got back to me letting me know it doesn't. One of them was nice enough to let me look into the issue per remote desktop.
I tried a lot of different NSPipe/NSFileHandle combination for StandardOutput/StandardError to make sure the problem is not related filling up these buffers. Example 1 and 2. My guess is that it is not related because it works fine on so many systems and _dyld_start is too early on in the application lifecycle to fill up StandardOutput/StandardError.
Other notes about the problem:
Launching the helper app from the terminal works fine.
Attaching and detaching the gdb on the stuck process and after-worth it works fine and when it finished NSTask picks up work after -waitUntilExit.
Using fork(2) and execv(3) instead of NSTask is able to launch and run the helper fine.
The parent process is sandboxed but I think previous reports where non-sandboxed on Mac OS X 10.6/10.7.
Screenshot of the process Sample from Activity Monitor:
Any clues or debugging tips to figure out why the helper is stuck in _dyld_start are welcome!
Since nobody answered, I am throwing a few ideas. Maybe one of them is the answer – only guessing – but since clues and tips are welcome, you could take a look at:
the list of the loaded libraries in the crash dump (there may be a clue there)
any error that would happen in the child process (after the fork). However, I see why it could be difficult to get back any post-fork error.
If I recall correctly, NSTask calls posix_spawn(2). This may be a clue, since using fork(2) and execv(3) seems working, you could focus on the differences between NSTask and the non-blocking alternative. Clearly, something is happening at the very beginning that prevents the child from executing properly.
Are you sure it is stuck and not crashed? As far as the user could tell, your app your app wouldn't look like it crashed. Only the child process would crash.
As a last resort, you could try to look for any Mach exception occuring (if
any, that would mean an error, which you wouldn't be able to
recover anyway. But it would provide valuable clues nonetheless).
You can tell willing custommers to send you their sysdiagnose. To this goal, ask them to hit Command + Option + Control + . + Shift to wait a few minutes. Soon after, their finder should pop a window to reveal a file named: sysdiagnose_timestamp_.tar.gz. Kindly ask them to mail it to you. Mine is around 5 MB. More details on the sysdiagnose man page.

Obj-C, how can I log to a file how long a method took in seconds?

I envisage I'll run into problems as i haven't done this before.
I'm thinking that I can either define a date at the start of the method or initialise a class.
Then at the end of the method, call the commit method, which will write the time taken about with some sort of code to determine where the measurement was made.
Since you're crashing before the app finishes launching, so no code is going to fix this. If TestFlightApp isn't working, any other code-based solutions are likely to have the same problem.
As #dasblinkenlight noted, NSLog timestamps, so that's a really easy first step. Then you need to get the logs.
If possible, have your user install and run the iPhone Configuration Utility. Have her connect her device and select it from the Devices list. Then select Console and "Save Console As..." She can then mail it to you.