0

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":

Empty UIActivityViewController

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.

oguz ismail
  • 1
  • 16
  • 47
  • 69
Kane Cheshire
  • 1,654
  • 17
  • 20

1 Answers1

1

I properly figured it out after taking a break and looking at the previous answer I posted. The reason it wasn't working is because I was passing an array of URLs inside of another array when creating the UIActivityViewController.

So this line: UIActivityViewController(activityItems: [logURLs], applicationActivities: nil)

Should be: UIActivityViewController(activityItems: logURLs, applicationActivities: nil)

Kane Cheshire
  • 1,654
  • 17
  • 20