Posts

Post not yet marked as solved
8 Replies
3.0k Views
Dear fellow developers, I have an issue where my didReceiveRemoteNotification method in the AppDelegate is never called. Here's what I did: I am developing a SwiftUI application for iOS 15 and 16 and am currently running tests in an iPhone 14 Pro Simulator. My Xcode version is 14.2 and the simulator is running iOS 16.2. I am of course talking about the AppDelegate's application:didReceiveRemoteNotification:fetchCompletionHandler: method, not the deprecated one. I embedded the AppDelegate in the following way: @main struct MyApp: App {     @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate ... } The integration of my AppDelegate does work in general, meaning the didFinishLaunchingWithOptions is called. I added the background modes capability to my app, including both "Remote notifications" and "Background processing". With this configuration, I would expect the AppDelegate's method to be called. I tried sending different push notifications with different payloads and headers while having the app both in the background and foreground but without success. Just to rule out mistakes on my side that are obvious to someone else, this is how I embedded the method into my AppDelegate: class AppDelegate: UIResponder, UIApplicationDelegate { ... func application( _ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void ) { print("Method called!") completionHandler(.noData) } } And here are a few payloads and headers that I tested. I tried all of the following payloads with the following headers in any combination. apns-push-type=alert or apns-push-type=background apns-priority=5 or apns-priority=10 Example 1: Visible notification { "aps": { "alert": { "body": "Test" }, "badge": 1, "content-available": 1 }, "test": "data" } Example 2: Silent notification without badge update { "aps": { "content-available": 1 }, "test": "data" } Example 3: Silent notification with empty alert block and badge update, based on ideas from this thread { "aps": { "alert": {}, "badge": 0, "content-available": 1 }, "test": "data" } As I said, no matter whether my app is in the foreground or background, the method is never called. At the same time, the userNotificationCenter(_:willPresent:withCompletionHandler:) method of the UNUserNotificationCenterDelegate is called when the app is in the foreground. At this point, I am running out of ideas what I could possibly be doing wrong, so I hope someone else has an idea what else to try.
Posted
by hoelska.
Last updated
.
Post marked as solved
1 Replies
508 Views
I stumbled into a very weird bug that seems to concern SwiftUI as a whole. I am able to reproduce the bug with the following very simple view: struct ContentView: View { @State private var sheetVisible = false var body: some View { VStack { Text("Some Button") .onTapGesture { sheetVisible = true } Spacer() } .sheet(isPresented: $sheetVisible) { Text("Sheet Content") } } } The steps to reproduce the bug are as follows: Tap on the button to open the sheet Move the app into the background with the sheet open Open the app again and pull down the sheet After that, the touch area of the button to open the sheet has moved down by approximately the height that the parent view is moved down visually when the sheet is open. Meaning, you cannot tap the button anymore, you have to tap way below the button. I am not sure whether I did something wrong, though I cannot really imagine that being the case with the bug existing in an example as simple as the above. My setup is as follows: Xcode 14.2 Build 14C18 iPhone 14 Pro Simulator with iOS 16.2 (however we can reproduce the bug on our real devices with an iPhone 11 Pro, 12 Pro and 13 Pro across different iOS versions for a while now) I filed a bug report but I also wanted to draw attention to the bug here and ask other developers to test whether they can confirm this is a bug and whether this affects their apps as well.
Posted
by hoelska.
Last updated
.