New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to retrieve log files from iOS App Extensions #439
Comments
Any update on this? |
I'm interested in a solution to this as well. |
I believe there is also a problem with the log file not getting flushed when the app extension terminates, as UIApplicationWillTerminateNotification or NSApplicationWillTerminateNotification aren't generated for an app extension. |
Guys, sorry for the lack of response here but at least myself have little experience with app extensions. It would be great if you could debug and find a solution |
Storing logs in an App Group's shared folder could be one way to make those logs accessible from the main app maybe? |
It is possible to store app extension logs in a shared container using the following: NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *containerUrl =
[fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.com.example.app"];
NSString *extensionLogDirectory =
[[containerUrl path] stringByAppendingPathComponent:@"AppExtensionLogs"];
id<DDLogFileManager> logFileManager =
[[DDLogFileManagerDefault alloc] initWithLogsDirectory:extensionLogDirectory];
DDFileLogger *fileLogger = [[DDFileLogger alloc] initWithLogFileManager:logFileManager]; However, you cannot download the shared container from XCode, so to read the logs, you can do the following in your app (e.g. in your app delegate): NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *containerUrl =
[fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.com.example.app"];
NSString *extensionLogDirectory =
[[containerUrl path] stringByAppendingPathComponent:@"AppExtensionLogs"];
NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:extensionLogDirectory
error:nil];
for (NSString *file in directoryContents) {
NSString *path = [extensionLogDirectory stringByAppendingPathComponent:file];
NSString *fileContents = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:nil];
DDLogInfo(@"File contents of %@ %@", path, fileContents);
} This isn't great, but it allows me to read the logs. A longer-term solution may be to have a background task that your app fires off when it loads to copy the logs into your main app's directory. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions. |
Closing per @ianjoneill 's comment. |
When using CocoaLumberjack with file logging on an iOS App Extension, like a Today's extension, the files are saved in the extension's container. Although this container is accessible in a Simulator, it is not on non jailbroken devices.
The only way I found to read the log file is through debugging the extension and printing the whole contents of the file in the console.
Since Apple does not allow extensions to access the main App's container, nor does it allow the app to access the extension's container, there is no way for one of them to migrate the log files to the other through code.
Downloading the App's container through:
Xcode -> Window -> Devices -> <YOUR-DEVICE> -> <YOUR-APP> -> Select gear -> Download container..
Only downloads the main app's container, which may have CocoaLumberjack's file logs from the app but not from the extension.
One possible solution for this would be using App Groups which allows both the app and an extension to share a container/directory, and setting CocoaLumberjack on both the App and the extension to save the log files into this directory, unfortunately I got an error when performing the write of the file.
What needs to change in CocoaLumberjack in order to give access to these log files to its users?
The text was updated successfully, but these errors were encountered: