Logging and such

This commit is contained in:
Philipp Heckel 2022-05-18 20:16:30 -04:00
parent e1bf9dda69
commit 2520ccef65
5 changed files with 104 additions and 37 deletions

View file

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "519DCFAE-6C1E-4F57-BEC5-8AD5D654CF3A"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "75468F65-9E01-4DF5-A169-07217AF6D1B2"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ntfyNSE/NotificationService.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "25"
endingLineNumber = "25"
landmarkName = "didReceive(_:withContentHandler:)"
landmarkType = "7">
<Locations>
<Location
uuid = "75468F65-9E01-4DF5-A169-07217AF6D1B2 - 427a5e501e23ebe0"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "ntfyNSE.NotificationService.didReceive(_: __C.UNNotificationRequest, withContentHandler: (__C.UNNotificationContent) -&gt; ()) -&gt; ()"
moduleName = "ntfyNSE"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/pheckel/Code/ntfy/ntfyNSE/NotificationService.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "25"
endingLineNumber = "25"
offsetFromSymbolStart = "516">
</Location>
<Location
uuid = "75468F65-9E01-4DF5-A169-07217AF6D1B2 - 427a5e501e23ebe0"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "ntfyNSE.NotificationService.didReceive(_: __C.UNNotificationRequest, withContentHandler: (__C.UNNotificationContent) -&gt; ()) -&gt; ()"
moduleName = "ntfyNSE"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/pheckel/Code/ntfy/ntfyNSE/NotificationService.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "25"
endingLineNumber = "25"
offsetFromSymbolStart = "560">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "57A50049-60E1-472C-ADB5-E4648E442C07"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ntfyNSE/NotificationService.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "32"
endingLineNumber = "32"
landmarkName = "didReceive(_:withContentHandler:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

View file

@ -28,12 +28,12 @@
<key>ntfy.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
<key>ntfyNSE.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>

View file

@ -17,6 +17,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
Log.d(tag, "ApplicationDelegate didFinishLaunchingWithOptions.")
// FirebaseApp.configure() DOES NOT WORK
FirebaseConfiguration.shared.setLoggerLevel(.max)
Messaging.messaging().delegate = self
@ -27,50 +28,38 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
guard let aps = userInfo["aps"] as? [String: AnyObject] else {
completionHandler(.failed)
return
}
print("didReceiveRemoteNotification")
print(userInfo)
}
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
print("didReceiveRemoteNotification 2")
guard let aps = userInfo["aps"] as? [String: AnyObject] else {
return
}
print(userInfo)
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
Log.d(tag, "Called didReceiveRemoteNotification (with completionHandler). This is a no-op.", userInfo)
}
func application(
_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error
didReceiveRemoteNotification userInfo: [AnyHashable: Any]
) {
print("Failed to register: \(error)")
Log.d(tag, "Called didReceiveRemoteNotification (without completionHandler). This is a no-op.", userInfo)
}
func application(
_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error
) {
Log.e(tag, "Failed to register for remote notifications", error)
}
// This function is added here only for debugging purposes, and can be removed if swizzling is enabled.
// If swizzling is disabled then this function must be implemented so that the APNs token can be paired to
// the FCM registration token.
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("APNs token retrieved: \(deviceToken)")
// With swizzling disabled you must set the APNs token here.
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
let token = deviceToken
.map { data in String(format: "%02.2hhx", data) }
.joined()
Log.d(tag, "Registered for remote notifications. Passing APNs token to Firebase: \(token)")
Messaging.messaging().apnsToken = deviceToken
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \(token)")
}
func registerForPushNotifications() {

View file

@ -20,6 +20,7 @@ class Store: ObservableObject {
let storeUrl = directory.appendingPathComponent("ntfy.sqlite")
let description = NSPersistentStoreDescription(url: storeUrl)
// Set up container and observe changes from app extension
container = NSPersistentContainer(name: "Model")
container.persistentStoreDescriptions = [description]
container.loadPersistentStores { description, error in
@ -27,6 +28,8 @@ class Store: ObservableObject {
print("Core Data failed to load: \(error.localizedDescription)")
}
}
// Shortcut for context
context = container.viewContext
}

View file

@ -26,7 +26,10 @@ class NotificationService: UNNotificationServiceExtension {
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
let userInfo = bestAttemptContent.userInfo
Store.shared.saveNotification(fromUserInfo: userInfo)
let store = Store.shared
store.saveNotification(fromUserInfo: userInfo)
contentHandler(bestAttemptContent)
}
}