test(ios): enhance sanity check logging with os_log and NSLog
Enhanced logging to ensure messages are captured: Logging Methods: - Added os_log for system logging (visible in Console.app) - Added NSLog for guaranteed output - Kept print() for Xcode console - Added emoji prefixes for easy filtering Logging Points: - ViewController initialization - Bridge existence check - WebView existence check - WebView URL logging - Sanity check execution Fixes: - Log visibility: messages now appear in multiple log streams - Debugging: can now see if ViewController is being created - WebView diagnosis: can see bridge and WebView state Result: Logs should now be visible in Console.app and log stream
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
import UIKit
|
||||
import Capacitor
|
||||
import WebKit
|
||||
import os.log
|
||||
|
||||
/**
|
||||
* Main view controller extending Capacitor's bridge view controller
|
||||
@@ -20,11 +21,15 @@ import WebKit
|
||||
*/
|
||||
class ViewController: CAPBridgeViewController {
|
||||
|
||||
private let logger = OSLog(subsystem: "com.timesafari.dailynotification", category: "ViewController")
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// SANITY CHECK: Try loading a simple HTML file directly
|
||||
print("ViewController: Starting sanity check...")
|
||||
os_log("🔍 ViewController: Starting sanity check...", log: logger, type: .info)
|
||||
print("🔍 ViewController: Starting sanity check...")
|
||||
NSLog("🔍 ViewController: Starting sanity check...")
|
||||
|
||||
// Wait a moment for Capacitor to initialize, then check
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
@@ -32,17 +37,30 @@ class ViewController: CAPBridgeViewController {
|
||||
}
|
||||
|
||||
// Debug: Print bridge configuration
|
||||
print("ViewController: Bridge initialized")
|
||||
os_log("🔍 ViewController: Bridge initialized", log: logger, type: .info)
|
||||
print("🔍 ViewController: Bridge initialized")
|
||||
NSLog("🔍 ViewController: Bridge initialized")
|
||||
|
||||
if let bridge = self.bridge {
|
||||
print("ViewController: Bridge found")
|
||||
os_log("✅ ViewController: Bridge found", log: logger, type: .info)
|
||||
print("✅ ViewController: Bridge found")
|
||||
NSLog("✅ ViewController: Bridge found")
|
||||
|
||||
if let webView = bridge.webView {
|
||||
print("ViewController: WebView found: \(webView)")
|
||||
print("ViewController: WebView URL: \(webView.url?.absoluteString ?? "nil")")
|
||||
let urlString = webView.url?.absoluteString ?? "nil"
|
||||
os_log("✅ ViewController: WebView found, URL: %{public}@", log: logger, type: .info, urlString)
|
||||
print("✅ ViewController: WebView found: \(webView)")
|
||||
print("✅ ViewController: WebView URL: \(urlString)")
|
||||
NSLog("✅ ViewController: WebView found, URL: %@", urlString)
|
||||
} else {
|
||||
print("ViewController: WebView is nil!")
|
||||
os_log("❌ ViewController: WebView is nil!", log: logger, type: .error)
|
||||
print("❌ ViewController: WebView is nil!")
|
||||
NSLog("❌ ViewController: WebView is nil!")
|
||||
}
|
||||
} else {
|
||||
print("ViewController: Bridge is nil!")
|
||||
os_log("❌ ViewController: Bridge is nil!", log: logger, type: .error)
|
||||
print("❌ ViewController: Bridge is nil!")
|
||||
NSLog("❌ ViewController: Bridge is nil!")
|
||||
}
|
||||
|
||||
// Initialize Daily Notification Plugin demo fetcher
|
||||
@@ -54,21 +72,30 @@ class ViewController: CAPBridgeViewController {
|
||||
* Sanity check: Try to load a simple HTML file to verify WebView works
|
||||
*/
|
||||
private func performSanityCheck() {
|
||||
print("ViewController: Performing sanity check...")
|
||||
os_log("🔍 ViewController: Performing sanity check...", log: logger, type: .info)
|
||||
print("🔍 ViewController: Performing sanity check...")
|
||||
NSLog("🔍 ViewController: Performing sanity check...")
|
||||
|
||||
// Check if we have a bridge and webView
|
||||
guard let bridge = self.bridge else {
|
||||
os_log("❌ SANITY CHECK FAILED: Bridge is nil!", log: logger, type: .error)
|
||||
print("❌ SANITY CHECK FAILED: Bridge is nil!")
|
||||
NSLog("❌ SANITY CHECK FAILED: Bridge is nil!")
|
||||
return
|
||||
}
|
||||
|
||||
guard let webView = bridge.webView else {
|
||||
os_log("❌ SANITY CHECK FAILED: WebView is nil!", log: logger, type: .error)
|
||||
print("❌ SANITY CHECK FAILED: WebView is nil!")
|
||||
NSLog("❌ SANITY CHECK FAILED: WebView is nil!")
|
||||
return
|
||||
}
|
||||
|
||||
let urlString = webView.url?.absoluteString ?? "nil"
|
||||
os_log("✅ Bridge and WebView exist, URL: %{public}@", log: logger, type: .info, urlString)
|
||||
print("✅ Bridge and WebView exist")
|
||||
print("WebView URL: \(webView.url?.absoluteString ?? "nil")")
|
||||
print("WebView URL: \(urlString)")
|
||||
NSLog("✅ Bridge and WebView exist, URL: %@", urlString)
|
||||
|
||||
// Try to load test.html directly
|
||||
if let bundlePath = Bundle.main.resourcePath,
|
||||
|
||||
Reference in New Issue
Block a user