— Xcode, Swift, symlinks — 2 min read
The real value/uniqueness on this page is showing how to use Console.app for push notifications. I also include some more basic guidance to help you avoid some common problems.
Launch the application from Xcode (run, but ensure your scheme uses the Debug build configuration, not release or profile) or AppCode (debug mode). Place breakpoints in methods that should be called to confirm that your methods are (not) being called. Some useful methods:
data, you won't be able to handle the notification in didReceiveRemoteNotification below. Instead, you can handle notification taps by the user, and decide to even show it if the app is in the foreground.didReceiveNotificationResponse:completionHandler:userNotificationCenter(_:willPresent:withCompletionHandler:)application(_:didReceiveRemoteNotification:fetchCompletionHandler:)application(_:didReceiveRemoteNotification:), the deprecated version.If showing an alert notification to the user, be sure to requestAuthorization to show notifications from the user. This is not required if you just want background messages, handling messages in didReceive(_:completionHandler:). It's really easy to forget this.
You should do this when first debugging. This allows you to test push notifications without having to structure a message correctly, since this file does it for you. This also reduces the complexity/ layers in the problem when first debugging, since 3rd party services (Ably's Channels or Firebase Cloud Messaging). If the device is registered correctly, it should receive this message. Make sure to update the TEAMID, KEYID, SECRET, BUNDLEID and DEVICETOKEN. My colleague shared this script with me:
Usage: Get direct_apns.sh from this GitHub Gist. Run chmod +x direct_apns.sh and execute it: ./direct_apns.sh.
apns-headers in Firebase at the wrong level of the JSON being sent to Firebase.Open Console.app (this is different to Terminal.app or iTerm2.app) installed on your mac. To confirm your application received the push message/ check for errors related to push notifications:
Be sure to start logging for the correct dvice. Then find relevant logs by:
com.apple.pushLaunchCANCELED: com.apple.pushLaunch. For example, this may show the log line: CANCELED: com.apple.pushLaunch.com.example.app:DBA43D at priority 10COMPLETED com.apple.pushLaunch. For example, this may show the log line COMPLETED com.apple.pushLaunch.package_name:XXXXXX at priority 5dasd process either by right clicking a log line with dasd and click Show Process 'dasd'.didReceiveRemoteNotification delegate method will be called, often within a few minutes. If you look in the Console.app logs, you may find sending the exact same message gives different outcomes:ThunderingHerdPolicy error (What really is the ThunderingHerdPolicy?): 1{name: ThunderingHerdPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{deviceInUse == 1 AND timeSinceThunderingHerdTriggerEvent < 900}]}}2 ], FinalDecision: Must Not Proceed}cameraIsActive error:1com.apple.pushLaunch.io.ably.flutter.plugin-example:4935F4:[2{name: MemoryPressurePolicy, policyWeight: 5.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{cameraIsActive == 1}]}}3], FinalDecision: Must Not Proceed}1{name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Proceed, Score: 1.00, Rationale: [{[appIsForeground]: Required:1.00, Observed:1.00},]}}2 ], FinalDecision: Absolutely Must Proceed}1com.apple.pushLaunch.io.ably.flutter.plugin-example:5E1C66:[2{name: DeviceActivityPolicy, policyWeight: 5.000, response: {Decision: Can Proceed, Score: 0.25}}3] sumScores:93.270000, denominator:97.020000, FinalDecision: Can Proceed FinalScore: 0.961348}I initially wrote this to add Push Notifications support to a Flutter library. There might be more useful content there.
There are 2 environments, sandbox and production.
Comment below with your issues and I'll try to help. APNs can be quite a frustrating experience, and I understand it a bit deeply now, and I'm happy to help. Or ask a Stack Overflow question and link it below.