Post

Replies

Boosts

Views

Activity

Notification Service Extension Fail to work
Hello, I've implemented Notification Service Extension as well as push notification in my app. I choose Notification Service Extension as the scheme and then run the whole project. The main app runs well. But when I send a message to my device, I immediately see an alert banner poping up. The content in it has not been modified, which indicates the Notification Service Extension does not work. Also I didn't see any logs printed out from the notification extension. At the meantime, below error messages have been printed out on console under the name of "TestAppPushNotificationExtension" **2022-04-22 00:20:14.818476-0700 TestAppPushNotificationExtension[3594:131852] Bogus event received by listener connection: <dictionary: 0x24e1cbb20> { count = 1, transaction: 0, voucher = 0x0, contents = "XPCErrorDescription" => <string: 0x24e1cbcb8> { length = 18, contents = "Connection invalid" } } 2022-04-22 00:20:17.797906-0700 TestAppPushNotificationExtension[3594:131852] [lifecycle] WARNING: Did not receive handshake message from the host after waiting ~2 seconds. THIS MAY BE A SPURIOUS LAUNCH OF THE PLUGIN due to a message to an XPC endpoint other than the main service endpoint, or the CPU is highly contended and this extension or its host is not getting enough CPU time. ** I've followed this article(https://www.amarendrasingh.com/swift/notification-service-extension-not-working/) and tried every recommended way to debug. But I still didn't find a way to resolve it...
0
0
604
Apr ’22
Notification Service extension is not called
I implemented a basic version of the Notification Service Extension but it doesn't get called. Would like to ask for an advice... 【Issue Description】 Step 1: Run the main app that contains the extension on my iPhone. Step 2: Set the breakpoints and add some logs in the extension. Step 3: Attach the extension to the process for debugging purpose. Besides the "scheme" section, it always shows “waiting to attach to Notification Service on Angel’s iPhone".  Step 4: Triggered the push notification when the device screen is locked. I immediately received a message which was apparently not modified. Step 5: The title -"Notification Service Extension" appears in console area. But no logs was printed out on the console. And no breakpoint was hit. So apparently this extension target was not invoked. 【Attempts I made】 1.Make sure "mutable-content: 1" is in notification payload; 2.Make sure an alert dictionary with "title" field is in notification payload; 3.Make sure TARGETS (main) -> Build Phases -> Embed App Extensions -> Uncheck "Copy only when installing" is unchecked; 4.Check the deployment version of both main app and the extension target(13.0) are lower than my device version(15.4). 5.Tried to explicitly & directly run the extension target but received an XPCError -"connection invalid". 6.Tried to create a new extension with minimal code but met with the exact same issue.
1
1
2.4k
Apr ’22
How to use Timer when app is in background
I'm developing Push Notification for our chat app. To enable Push Notification, our app will register the device token as well as some other information to another independent service, let's say "RegistrationService". Then any message going through the "RegistrationService" will know which device it should be sent to. Now my issue is - Since every registration record in "RegistrationService" has a TTL of 24 hour, our app will need to do another registration once the expiration time is reached. Currently I use the below codes in AppDelegate to start push notification and do the first time registration. I'm thinking if it is possible to resolve the above mentioned issue by embedding a "Timer". If so, can the timer work well when app is running in background? As we know, Push Notification offers a solution for client to receive the message when app in background. If the timer/registration auto-renew doesn't work in background, it can be a big issue. (From this post, https://developer.apple.com/forums/thread/127444, looks like the timer can't work when app is in background. If so, do you have any other recommended ways to achieve this?)     func application(     _ application: UIApplication,     didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data     ) {         let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }         let token = tokenParts.joined()         print("Device Token: \(token)")         UserDefaults.standard.set(token, forKey: "APNSToken")         // Start push notifications         guard let apnsToken = UserDefaults.standard.string(forKey: "APNSToken") else {             print("Failed to get APNS token")             return         }         let semaphore = DispatchSemaphore(value: 0)         DispatchQueue.global(qos: .background).async { [weak self] in             guard let self = self else { return }             guard let chatClient = self.chatClient else { return }             chatClient.startPushNotifications(deviceToken: apnsToken) { result in                 switch result {                 case .success:                     print("Started Push Notifications")                 case let .failure(error):                     print("Failed To Start Push Notifications: \(error)")                 }                 semaphore.signal()             }             semaphore.wait()         }     }
1
0
1k
Apr ’22
Keychain items deleted Error -34018
I tried to perform the troubleshooting steps in this post - https://developer.apple.com/forums/thread/114456 As it instructs, "The first step in troubleshooting this problem is to check your app’s entitlements. To start, use the codesign tool to dump the entitlements" $ codesign -d --entitlements :- /path/to/your.app I don't know what to put as " /path/to/your.app". I didn't find any file ending in ".app".
2
0
574
Apr ’22
Can't handle Push Notification when app is running in background
Hello, I'm developing Push Notification on IOS 13 for our chat app. I want to achieve the below scenario - When the chat app is running in background and the device receives a chat message, (1) the user can see an alert banner popping up; (2) the app can receive the push notification payload inside this block - "application(_:didReceiveRemoteNotification:fetchCompletionHandler:)", which is in App Delegate. From this wiki (https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application), I assume these can be achieved. Now I succeeded in (1) but failed in (2). This "didReceiveRemoteNotification" can never be invoked when the app is in background... FYI - when the app is running in foreground, the "didReceiveRemoteNotification" can be called. Not sure if my testing method is correct...I connect my physical iPhone with the MacBook, open the program in Xcode and hit "run" button in Xcode to run this program. 3.Below please my notification template - "{"aps":{"mutable-content":1,"sound":"default", "alert":{"title":"New Message"}},"data": "customized content"} I'm not sure if I will need to add "content-available: 1" as well. Thanks for your answer!
0
0
693
Apr ’22
How to generate an AES key in swift
Hello all, I'm developing IOS Push Notification。 I'll need to generate an AES key and register the key to another backend service so they can encrypt the notification payload using AES-256 cryptography. But based on the official Apple Developer doc (https://developer.apple.com/documentation/security/certificate_key_and_trust_services/keys/generating_new_cryptographic_keys#2863927), I didn't find a way to generate such a symmetric encryption key. All I found is how to create an asymmetric one. Has Anybody created an AES key in swift before? Your help is much appreciated
5
0
3.9k
Apr ’22