<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Atanu Mondal on Medium]]></title>
        <description><![CDATA[Stories by Atanu Mondal on Medium]]></description>
        <link>https://medium.com/@mondal.atanu2007?source=rss-f5930e0a2d8b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PsCSu8ElWcct-JD099M4ng.jpeg</url>
            <title>Stories by Atanu Mondal on Medium</title>
            <link>https://medium.com/@mondal.atanu2007?source=rss-f5930e0a2d8b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 09:36:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mondal.atanu2007/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Use Custom Action in Local and Push Notifications for iOS App]]></title>
            <link>https://medium.com/codelogicx/how-to-use-custom-action-in-local-and-push-notifications-for-ios-app-501d202d7301?source=rss-f5930e0a2d8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/501d202d7301</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[push-notification]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[actionable-push]]></category>
            <dc:creator><![CDATA[Atanu Mondal]]></dc:creator>
            <pubDate>Tue, 19 Nov 2024 17:16:50 GMT</pubDate>
            <atom:updated>2024-11-19T17:16:50.507Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i1kx-j78XFXvlJaiL8wwgA.jpeg" /></figure><p><strong>Actionable Notifications</strong> (also known as <strong>interactive notifications</strong>) are a type of notification that allows users to take action directly from the notification itself. This can be useful in many scenarios, such as confirming an appointment, replying to a message, or marking a task as complete, all without needing to open the app.</p><p>If you haven’t already set up push notifications for your iOS app, <a href="https://medium.com/codelogicx/how-to-configure-push-notifications-in-ios-app-db93c2c85815">here’s</a> a quick overview of the essential steps involved in configuring them. Make sure you’ve followed this process before continuing with actionable notifications.</p><p>Here’s a breakdown of how actionable notifications work on iOS:</p><h3>1. Creating and Registering a Category and Actions</h3><p>In iOS, actionable notifications can have buttons with specific actions attached to them. This is done by creating a UNNotificationAction for each button and associating them with a UNNotificationCategory.</p><p><strong>Example:</strong></p><pre>import UserNotifications<br><br>// Step 1: Create actions for the notification<br>let acceptAction = UNNotificationAction(identifier: &quot;custom_accept&quot;, title: &quot;Accept&quot;, options: [])<br>let declineAction = UNNotificationAction(identifier: &quot;custom_decline&quot;, title: &quot;Decline&quot;, options: [.destructive])<br><br>// Step 2: Create a category for the actions<br>let customCategory = UNNotificationCategory(identifier: &quot;customCategory&quot;, <br>                                             actions: [acceptAction, declineAction], <br>                                             intentIdentifiers: [], <br>                                             options: [])<br><br>// Register the category with UNUserNotificationCenter<br>UNUserNotificationCenter.current().setNotificationCategories([customCategory])</pre><p>Here, we define two actions: <strong>Accept</strong> and <strong>Decline</strong>, with the <strong>Decline</strong> action marked as destructive (to indicate that it is a negative action).</p><h3>2. Setting the Category on a Local Notification</h3><p>To apply the actions you’ve just created to a <strong>local notification</strong>, you need to set the categoryIdentifier property of the notification&#39;s content.</p><pre>// Step 3: Create a local notification with a category identifier<br>let content = UNMutableNotificationContent()<br>content.title = &quot;Hello World!&quot;<br>content.body = &quot;This is the time to check push notification&quot;<br>content.sound = .default<br>content.categoryIdentifier = &quot;customCategory&quot;  // Set the category<br><br>// Create a trigger (for example, triggering in 5 seconds)<br>let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)<br><br>// Create the request with the content and trigger<br>let request = UNNotificationRequest(identifier: &quot;notification_1&quot;, <br>                                    content: content, <br>                                    trigger: trigger)<br><br>// Add the notification request to the notification center<br>UNUserNotificationCenter.current().add(request) { error in<br>    if let error = error {<br>        print(&quot;Error scheduling notification: \(error.localizedDescription)&quot;)<br>    }<br>}</pre><h3>3. Adding Category to Push Notification Payload</h3><p>For <strong>push notifications</strong>, you can also specify category in the payload when sending the notification from the server. The category key in the payload corresponds to the categoryIdentifier one you registered earlier.</p><p><strong>Example push notification payload:</strong></p><pre>{<br>   &quot;aps&quot;: {<br>      &quot;alert&quot;: {<br>         &quot;title&quot;: &quot;Hello World!&quot;,<br>         &quot;body&quot;: &quot;This is the time to check push notification&quot;<br>      },<br>      &quot;badge&quot;: 1,<br>      &quot;sound&quot;: &quot;default&quot;,<br>      &quot;category&quot;: &quot;customCategory&quot;  // Set the category here<br>   }<br>}</pre><h3>4. Handling Notification Actions</h3><p>When a user taps one of the action buttons on the notification, the app will be launched in the background and the delegate method userNotificationCenter(_:didReceive:withCompletionHandler:) will be called. You can use this method to handle the user’s choice.</p><p>Make sure your app has set up a notification delegate by implementing the necessary protocol in the AppDelegate or in a relevant class:</p><pre>import UserNotifications<br><br>class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {<br><br>    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {<br>        // Request for notification permissions<br>        UNUserNotificationCenter.current().delegate = self<br>        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in<br>            if granted {<br>                print(&quot;Notification permission granted.&quot;)<br>            } else {<br>                print(&quot;Notification permission denied.&quot;)<br>            }<br><br>            guard granted else { return }<br>                <br>            // Step 1: Create actions for the notification<br>            let acceptAction = UNNotificationAction(identifier: &quot;custom_accept&quot;, title: &quot;Accept&quot;, options: [])<br>            let declineAction = UNNotificationAction(identifier: &quot;custom_decline&quot;, title: &quot;Decline&quot;, options: [.destructive])<br><br>            // Step 2: Create a category for the actions<br>            let customCategory = UNNotificationCategory(identifier: &quot;customCategory&quot;,<br>                                                             actions: [acceptAction, declineAction],<br>                                                             intentIdentifiers: [],<br>                                                             options: [])<br><br>            // Register the category with UNUserNotificationCenter<br>            UNUserNotificationCenter.current().setNotificationCategories([customCategory])<br>        }<br>        return true<br>    }<br><br>    // Handle the action when the notification is interacted with<br>    func userNotificationCenter(_ center: UNUserNotificationCenter, <br>                                didReceive response: UNNotificationResponse, <br>                                withCompletionHandler completionHandler: @escaping () -&gt; Void) {<br><br>        let actionIdentifier = response.actionIdentifier<br>        let userInfo = response.notification.request.content.userInfo<br><br>        print(&quot;User Info:&quot;, userInfo)<br>        print(&quot;Action Identifier:&quot;, actionIdentifier)<br><br>        switch actionIdentifier {<br>        case &quot;custom_accept&quot;:<br>            // Handle accept action<br>            print(&quot;User accepted the notification.&quot;)<br>            // Perform specific task for &#39;Accept&#39; action<br>        case &quot;custom_decline&quot;:<br>            // Handle decline action<br>            print(&quot;User declined the notification.&quot;)<br>            // Perform specific task for &#39;Decline&#39; action<br>        default:<br>            break<br>        }<br><br>        // Always call the completion handler when done<br>        completionHandler()<br>    }<br>}</pre><h3>Key Points:</h3><ol><li><strong>Category &amp; Action Registration:</strong></li></ol><ul><li>You must register the notification categories at the launch of the app (usually in application(_:didFinishLaunchingWithOptions:)).</li></ul><p><strong>2. Handling Action Responses:</strong></p><ul><li>When a user taps an action button (e.g., “Accept” or “Decline”), the app is notified via the userNotificationCenter(_:didReceive:withCompletionHandler:) method, where you can handle the response.</li></ul><p><strong>3. Push Notification Payload:</strong></p><ul><li>When sending a remote push notification, ensure that the payload includes the category key to specify which actions to display.</li></ul><h3>Common Issues:</h3><ul><li><strong>The app is not registered for remote notifications:</strong> Ensure that the app has permission to send and receive push notifications. This includes setting up the push notification capabilities in Xcode and registering for remote notifications (UIApplication.shared.registerForRemoteNotifications()).</li><li><strong>Action identifiers mismatch:</strong> Ensure that the identifiers used in the payload (&quot;custom_accept&quot;, &quot;custom_decline&quot;) match exactly with the ones used in the code where you define your actions.</li></ul><h3>Conclusion:</h3><p>With these steps, you can implement actionable notifications for both local and push notifications in your iOS app. You’ll allow users to interact with your app directly from the notification interface, improving user engagement and responsiveness.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=501d202d7301" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codelogicx/how-to-use-custom-action-in-local-and-push-notifications-for-ios-app-501d202d7301">How to Use Custom Action in Local and Push Notifications for iOS App</a> was originally published in <a href="https://medium.com/codelogicx">codelogicx</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Configure Push Notifications in iOS App]]></title>
            <link>https://medium.com/codelogicx/how-to-configure-push-notifications-in-ios-app-db93c2c85815?source=rss-f5930e0a2d8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/db93c2c85815</guid>
            <category><![CDATA[apn]]></category>
            <category><![CDATA[push-notification]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Atanu Mondal]]></dc:creator>
            <pubDate>Fri, 08 Nov 2024 12:55:07 GMT</pubDate>
            <atom:updated>2024-11-08T12:55:07.882Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E4F77OzMuSYDJbjt" /><figcaption>Photo by <a href="https://unsplash.com/@jamie452?utm_source=medium&amp;utm_medium=referral">Jamie Street</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Configuring push notifications in an iOS app involves several key steps, from registering for notifications, and handling their receipt, to sending them via a backend service like APNs or Firebase Cloud Messaging. Below is a detailed guide to implementing push notifications in iOS using SwiftUI and UIKit:</p><h3>Step 1: Register for Push Notifications</h3><h4>a. Enable Push Notifications in Xcode</h4><ol><li>Open your project in <strong>Xcode</strong>.</li><li>Select your target and go to the <strong>Signing &amp; Capabilities</strong> tab.</li><li>Add the <strong>Push Notifications</strong> entitlement.</li></ol><p>You can do this by clicking the “+” button at the top left and selecting “Push Notifications” from the list of capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1u1mwju-9t-CtcZcfsqCrQ.png" /></figure><h4>b. Register for Push Notifications in AppDelegate</h4><p>Since <strong>AppDelegate.swift</strong> is no longer automatically generated in SwiftUI-based projects, you’ll need to create it manually and then configure it.</p><ol><li>Create a custom class named AppDelegate that conforms to UIApplicationDelegate.</li><li>Implement the push notification registration process in the application(_:didFinishLaunchingWithOptions:) method.</li></ol><pre>import UIKit<br>import UserNotifications<br><br>class AppDelegate: NSObject, UIApplicationDelegate {<br>    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -&gt; Bool {<br>        print(&quot;App has finished launching&quot;)<br>        self.registerForPushNotifications()<br>        return true<br>    }<br>}<br><br>extension AppDelegate {<br>    func registerForPushNotifications() {<br>        // Request user permission for push notifications<br>        UNUserNotificationCenter.current().delegate = self<br>        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in<br>            print(&quot;Push Notification permission granted: \(granted)&quot;)<br>            if granted {<br>                self.getNotificationSettings()<br>            }<br>        }<br>    }<br><br>    // Get notification settings after user consent<br>    func getNotificationSettings() {<br>        UNUserNotificationCenter.current().getNotificationSettings { settings in<br>            print(&quot;Notification settings: \(settings)&quot;)<br>            guard settings.authorizationStatus == .authorized else { return }<br>            DispatchQueue.main.async {<br>                UIApplication.shared.registerForRemoteNotifications()<br>            }<br>        }<br>    }<br><br>    // Handle the device token registration<br>    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {<br>        let tokenParts = deviceToken.map { data in String(format: &quot;%02.2hhx&quot;, data) }<br>        let token = tokenParts.joined()<br>        print(&quot;Device Token: \(token)&quot;)<br>        // Send this token to your backend for push notification targeting<br>    }<br><br>    // Handle failure to register for push notifications<br>    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {<br>        print(&quot;Failed to register: \(error.localizedDescription)&quot;)<br>    }<br>}</pre><p>3. Use the @UIApplicationDelegateAdaptor property wrapper in the main App struct to connect your AppDelegate class to your app:</p><pre>@main<br>struct DemoNotificationApp: App {<br>    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate<br>    <br>    var body: some Scene {<br>        WindowGroup {<br>            ContentView()<br>        }<br>    }<br>}</pre><h3>Step 2: Handle Push Notification Receipt</h3><p>To handle the push notification when the app is in the foreground or background, you need to implement the UNUserNotificationCenterDelegate methods.</p><ol><li><strong>Foreground Handling</strong>: When the app is running and receives a notification, this method is called to decide how the notification should be presented.</li><li><strong>Background or Terminated Handling</strong>: This method is called when the app is in the background or terminated and the user taps the notification.</li></ol><p>Add these methods in the AppDelegate:</p><pre>extension AppDelegate: UNUserNotificationCenterDelegate {<br>    <br>    // Called when the app is in the foreground and a notification is received<br>    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -&gt; Void) {<br>        // Display notification as a banner, badge, and/or sound<br>        completionHandler([.banner, .badge, .sound])<br>    }<br>    <br>    // Called when a notification is tapped by the user<br>    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -&gt; Void) {<br>        let userInfo = response.notification.request.content.userInfo<br>        print(&quot;Notification userInfo: \(userInfo)&quot;)<br>        <br>        // Handle the notification (e.g., navigate to specific screen or show alert)<br>        <br>        completionHandler()<br>    }<br>}</pre><h3>Step 3: Send Push Notifications (Backend Integration)</h3><p>To send push notifications to the devices, you need a backend server that interacts with <strong>Apple Push Notification Service (APNs)</strong>. Here’s a simplified example of the payload structure you’ll send from your backend:</p><h4>Example Push Notification Payload:</h4><pre>{<br>   &quot;aps&quot;: {<br>      &quot;alert&quot;: {<br>         &quot;title&quot;: &quot;Hello World!&quot;,<br>         &quot;body&quot;: &quot;Check out the latest update!&quot;<br>      },<br>      &quot;badge&quot;: 1,<br>      &quot;sound&quot;: &quot;default&quot;,<br>      &quot;category&quot;: &quot;myCategory&quot;<br>   }<br>}</pre><h4>Backend Setup (using APNs or FCM)</h4><p>You can send push notifications using services like <strong>APNs</strong> (Apple Push Notification Service) or <strong>Firebase Cloud Messaging (FCM)</strong>. Here’s a basic overview of how you might send a notification via APNs:</p><ol><li><strong>APNs Authentication</strong>: You’ll need to authenticate with APNs using a certificate or token-based authentication.</li><li><strong>Send the Payload</strong>: The backend sends the payload to APNs along with the device token that your app received earlier.</li></ol><p><strong>Sample Code to Send Push Notification via APNs (Python example):</strong></p><pre>import requests<br>import json<br><br>def send_push_notification(device_token, payload):<br>    url = &#39;https://api.push.apple.com/3/device/&#39; + device_token<br>    headers = {<br>        &#39;Authorization&#39;: &#39;Bearer &lt;APNs Auth Token&gt;&#39;,<br>        &#39;apns-topic&#39;: &#39;&lt;your app bundle identifier&gt;&#39;,<br>        &#39;Content-Type&#39;: &#39;application/json&#39;,<br>    }<br>    <br>    response = requests.post(url, headers=headers, json=payload)<br>    print(response.status_code, response.text)<br><br>device_token = &#39;user_device_token_here&#39;<br>payload = {<br>    &quot;aps&quot;: {<br>        &quot;alert&quot;: {<br>            &quot;title&quot;: &quot;Hello World!&quot;,<br>            &quot;body&quot;: &quot;This is a test push notification.&quot;<br>        },<br>        &quot;badge&quot;: 1,<br>        &quot;sound&quot;: &quot;default&quot;<br>    }<br>}<br><br>send_push_notification(device_token, payload)</pre><h3>Conclusion</h3><p>By following these steps, you can integrate push notifications into your iOS app. The app will be able to:</p><ul><li>Request and handle user permissions for notifications.</li><li>Register for push notifications and receive the device token.</li><li>Handle incoming notifications, both when the app is in the foreground and when tapped.</li><li>Communicate with your backend to send push notifications to the correct device.</li></ul><p>Make sure to test push notifications on a real device, as they don’t work in the iOS simulator. Also, ensure your app’s provisioning profiles and certificates are properly set up for push notifications on Apple’s Developer portal.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db93c2c85815" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codelogicx/how-to-configure-push-notifications-in-ios-app-db93c2c85815">How to Configure Push Notifications in iOS App</a> was originally published in <a href="https://medium.com/codelogicx">codelogicx</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>