In one of my apps in the past I was able to allow users to export CocoaLumberjack logs from the device, using UIActivityViewController
, passing in an array of file URLs pointing to the logs on the user's device.
However even though I (think I) have ported over the same code from my older app, I cannot get any options to show in UIActivityViewController either on a device or the simulator. All I get is "more":
In my other app I get options to share to Slack, Mail, Files, etc like most other files.
To try and understand what I'm doing wrong I created a sample project but I'm still getting the same issue. The code is very simple so I'm now at a loss for what could be the issue, I know it's possible because I've got it working (somehow) in another app. Here's the code from the sample app:
AppDelegate.swift
import CocoaLumberjack
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
DDLog.add(DDOSLogger.sharedInstance)
let fileLogger = DDFileLogger()
fileLogger.rollingFrequency = 60 * 60 * 24
fileLogger.logFileManager.maximumNumberOfLogFiles = 7
DDLog.add(fileLogger)
DDLogInfo("Did finish launching")
return true
}
}
ViewController.swift
import CocoaLumberjack
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
DDLogInfo("View did load")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
guard let fileLogger = DDLog.allLoggers.compactMap({ $0 as? DDFileLogger }).first else { fatalError() }
let logURLs = fileLogger.logFileManager.sortedLogFilePaths.map { URL(fileURLWithPath: $0) }
let controller = UIActivityViewController(activityItems: [logURLs], applicationActivities: nil)
present(controller, animated: true)
}
}
I've tripled checked that the logs exist on disk, both on device and on the simulator and they do. If I inspect the URLs in the logURLs
constant I can navigate to the logs on disk and even open them in Console just fine like any other logs.