<?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 Ashwani Kumar on Medium]]></title>
        <description><![CDATA[Stories by Ashwani Kumar on Medium]]></description>
        <link>https://medium.com/@ashwani.cse4?source=rss-b4eff866468b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TR0IhFsAOaE6EYf1.jpg</url>
            <title>Stories by Ashwani Kumar on Medium</title>
            <link>https://medium.com/@ashwani.cse4?source=rss-b4eff866468b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 13:57:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashwani.cse4/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[Simplifying iOS App Invocation Handling with Swift: A Comprehensive Guide]]></title>
            <link>https://medium.com/@ashwani.cse4/simplifying-ios-app-invocation-handling-with-swift-a-comprehensive-guide-8ed03f7a2e5a?source=rss-b4eff866468b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ed03f7a2e5a</guid>
            <category><![CDATA[app-delegate]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Ashwani Kumar]]></dc:creator>
            <pubDate>Wed, 13 Sep 2023 18:07:48 GMT</pubDate>
            <atom:updated>2023-09-13T18:07:48.579Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*paV7N04EouBE02qc.png" /></figure><p>In the world of mobile app development, understanding how your app is launched and invoked is crucial for providing a seamless user experience. iOS apps can be opened in various ways, such as from a deep link, a notification click, or simply tapping the app icon. In this article, we’ll explore how to determine the app’s entry point using Swift, and we’ll introduce a practical use case to illustrate the concept.</p><h3>The AppInvocationType Enum</h3><p>Let’s start by defining an AppInvocationType enum that represents the different ways your iOS app can be invoked:</p><pre>enum AppInvocationType {<br>    case deepLink(url: URL)<br>    case notification(userInfo: [AnyHashable: Any])<br>    case appIconClick<br>    case unknown<br>}</pre><ul><li>deepLink(url: URL): The app is invoked via a deep link with a specific URL.</li><li>notification(userInfo: [AnyHashable: Any]): The app is opened in response to a notification click, and it receives user info associated with the notification.</li><li>appIconClick: The app is launched by tapping its icon on the home screen.</li><li>unknown: The app is opened in an unknown manner.</li></ul><h3>The GetAppInvocationTypeUseCase Class</h3><p>To determine the app’s entry point and return the appropriate AppInvocationType, we can create a GetAppInvocationTypeUseCaseclass:</p><pre>class GetAppInvocationTypeUseCase {<br>    private let userActivityKey = &quot;UIApplicationLaunchOptionsUserActivityKey&quot;<br>    private let launchOptions: [UIApplication.LaunchOptionsKey: Any]?<br>    <br>    init(launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {<br>        self.launchOptions = launchOptions<br>    }<br>    <br>    func invoke() -&gt; AppInvocationType {<br>        guard let launchOptions = launchOptions else { return .appIconClick }<br>        <br>        if let dictionary = launchOptions[UIApplication.LaunchOptionsKey.userActivityDictionary] as? [AnyHashable: Any] {<br>            guard let url = (dictionary[userActivityKey] as? NSUserActivity)?.webpageURL else { return .unknown }<br>            return .deepLink(url: url)<br>        }<br>        <br>        if let userInfo =<br>            launchOptions[UIApplication.LaunchOptionsKey.remoteNotification] as? [String: AnyObject] {<br>            return .notification(userInfo: userInfo)<br>        } else if launchOptions[UIApplication.LaunchOptionsKey.sourceApplication] == nil {<br>            return .appIconClick<br>        } else {<br>            return .unknown<br>        }<br>    }<br>}</pre><h3>Key Components Explained:</h3><ul><li><strong>Initialization</strong>: The init(launchOptions:) method initializes the use case with the provided launchOptions dictionary, typically passed to application(_:didFinishLaunchingWithOptions:) in the AppDelegate.</li><li><strong>invoke() Method</strong>: This method serves as the primary entry point for determining how the app was launched. It returns an AppInvocationType enum, indicating the app&#39;s launch type.</li><li><strong>Deep Link Handling:</strong> The code begins by checking for the presence of a deep link. It examines the userActivityDictionary within launchOptions, ensuring it&#39;s a browsing web activity. If validated, it extracts the URL and returns .deepLink(url:).</li><li><strong>Notification Handling:</strong> Next, it assesses whether a remote notification payload is present. If found, it returns .notification(userInfo:) with the associated user info.</li><li><strong>App Icon Click:</strong> If none of the previous conditions apply, the code verifies if sourceApplication is nil, signaling that the app was launched by tapping its icon. In this scenario, it returns .appIconClick.</li><li><strong>Unknown:</strong> If none of the conditions align, the method returns .unknown to denote an unrecognized app invocation.</li></ul><h3>Practical Use Case</h3><p>Now, let’s explore a practical use case for this code. Imagine you have a news app that supports deep linking. Users can open articles directly from external links. You want to determine how users accessed your app so you can provide a tailored experience.</p><pre>@UIApplicationMain<br>class AppDelegate: UIResponder, UIApplicationDelegate {<br><br>    var window: UIWindow?<br><br>    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {<br>        <br>        let getAppInvocationTypeUseCase = GetAppInvocationTypeUseCase(launchOptions: launchOptions)<br>        let invocationType = getAppInvocationTypeUseCase.invoke()<br>        <br>        switch invocationType {<br>        case .deepLink(let url):<br>            print(&quot;App was invoked from a deep link. URL: \(url.absoluteString)&quot;)<br>            // Handle deep link URL<br>            <br>        case .notification(let userInfo):<br>            print(&quot;App was invoked from a notification click. UserInfo: \(userInfo)&quot;)<br>            // Handle notification data<br>            <br>        case .appIconClick:<br>            print(&quot;App was invoked from the app icon.&quot;)<br>            // Handle app icon click<br>            <br>        case .unknown:<br>            print(&quot;App was invoked in an unknown manner.&quot;)<br>        }<br>        <br>        return true<br>    }<br>    <br>    // Other AppDelegate methods...<br>}</pre><p>In this use case, you’re using the GetAppInvocationTypeUseCase class to determine the app&#39;s entry point. Based on the invocation type, you can customize the user experience. For example, when the app is opened from a deep link, you can directly display the linked article. When opened from a notification, you can show the relevant news story.</p><h3>Conclusion</h3><p>Understanding how your iOS app is invoked is essential for building user-friendly experiences. By implementing the AppInvocationType enum and the GetAppInvocationTypeUseCase class, you can efficiently determine the app&#39;s entry point and tailor your app&#39;s behavior accordingly. This knowledge allows you to provide a seamless and context-aware user experience, enhancing user engagement with your app.</p><p><strong>If you found this article helpful and informative, please consider giving it a round of applause or claps to show your appreciation! Your feedback and support are greatly valued. Thank you for reading! 👏👏👏</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ed03f7a2e5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Merge, CombineLatest, and Zip: Comparing Operators of RxSwift for iOS]]></title>
            <link>https://medium.com/@ashwani.cse4/merge-combinelatest-and-zip-comparing-operators-of-rxswift-for-ios-2aff08049241?source=rss-b4eff866468b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2aff08049241</guid>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[rxswift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[rxcocoa]]></category>
            <dc:creator><![CDATA[Ashwani Kumar]]></dc:creator>
            <pubDate>Sat, 15 Apr 2023 12:17:30 GMT</pubDate>
            <atom:updated>2023-04-15T12:17:30.739Z</atom:updated>
            <content:encoded><![CDATA[<p>RxSwift is a popular reactive programming framework that provides a range of operators to manipulate and transform streams of events. Among these operators, Merge, combineLatest, and Zip are frequently used to combine or merge multiple streams into a single stream. In this article, we will discuss these operators, their differences, and when to use each one.</p><h3><strong>Merge Operator</strong></h3><p>The Merge operator is used to combine multiple streams of same type into a single stream. It takes two or more observables as input and produces a new observable that emits events from all the input observables in the order they are received. Here’s an example:</p><pre>let disposeBag = DisposeBag()<br>let disposeBag = DisposeBag()<br>let observable1 = PublishRelay&lt;Int&gt;()<br>let observable2 = PublishRelay&lt;Int&gt;()<br>let mergedObservable = Observable.merge(observable1.asObservable(), observable2.asObservable())<br><br>mergedObservable.subscribe(onNext: { value in<br>    print(value)<br>}).disposed(by: disposeBag)<br><br>observable1.accept(1)<br>observable2.accept(2)<br>observable1.accept(3)<br>observable2.accept(4)<br>observable2.accept(5)<br><br>//OUTPUT:-<br>//1<br>//2<br>//3<br>//4<br>//5</pre><p>The above code is creating two instances of PublishRelay&lt;Int&gt; class, which are used to emit integer values. The PublishRelay is a special type of RxSwift Subject that can emit values to its subscribers.</p><p>Next, it creates a merged observable mergedObservable by using the Observable.merge operator to combine the two observables (observable1 and observable2).</p><p>Then, it subscribes to mergedObservable and prints each emitted value using the subscribe method. This subscription will print out all the emitted values from the observable1 and observable2.</p><p>The DisposeBag is used to dispose of any subscriptions when the object is deallocated. In this case, the subscription to mergedObservable is added to the DisposeBag using the disposed(by:) method.</p><p>Finally, the code pushes/send/accepts values on observable1 and observable2 by using the accept method. The emitted values are 1, 2, 3, 4, and 5, respectively, as they are emitted from the <strong>Merged</strong> observable.</p><h3>CombineLatest Operator</h3><p>The combineLatest operator is used to combine the latest emitted values from multiple observables of any type into a single observable. It takes any number of observables as its parameters and returns a new observable that <strong><em>emits a tuple</em></strong> of the latest values from all the input observables whenever any of the input observables emits a new value.</p><p>Here’s an example:</p><pre>let disposeBag = DisposeBag()<br>let temperatureRelay = PublishRelay&lt;Int&gt;()<br>let humidityRelay = PublishRelay&lt;Int&gt;()<br>let combinedObservable = Observable.combineLatest(temperatureRelay.asObservable(), humidityRelay.asObservable())<br><br>combinedObservable.subscribe(onNext: { temperature, humidity in<br>    print(&quot;Temperature: \(temperature), Humidity: \(humidity)&quot;)<br>}).disposed(by: disposeBag)<br><br>temperatureRelay.accept(72) // No output yet<br>humidityRelay.accept(45)     // Output: Temperature: 72, Humidity: 45<br>temperatureRelay.accept(74) // // Output: Temperature: 74, Humidity: 45</pre><p>In this code, we create two PublishRelay objects - temperatureRelay and humidityRelay - which are used to emit temperature and humidity values. PublishRelay is a type of RxSwift Subject that allows emitting new elements to subscribers.</p><p>Then, we use the combineLatest operator to create a new Observable, weatherPublisher, that combines the <strong><em>latest values</em></strong> from temperatureRelay and humidityRelay. The combineLatest operator emits a new combined element whenever any of the source observables emit a new value.</p><p>Next, we subscribe to weatherPublisher using the subscribe(onNext:) method. This method takes a closure as its argument, which is called each time a new element is emitted by the Observable. In this case, the closure prints the latest values of temperature and humidity to the console.</p><p>Finally, we emit some values to temperatureRelay and humidityRelay using the accept method. When we emit 72 to temperatureRelay, no output is printed because there is no value emitted by humidityRelay yet. When we emit 45 to humidityRelay, the subscription to weatherPublisher outputs &quot;Temperature: 72, Humidity: 45&quot; because there is now at least one value emitted by both relays. Similarly, when we emit 74 to temperatureRelay, the subscription outputs &quot;Temperature: 74, Humidity: 45&quot; because the latest value from humidityRelay is still 45.</p><h3>Zip Operator:</h3><p>The Zip operator is used to combine the events of multiple observables into a single observable. It takes two or more observables as input and produces a new observable that emits events only <strong>when all the input observables have emitted an event</strong>. The emitted event is a combination of the latest events from all the input observables.</p><p>Here is an example:</p><pre>let disposeBag = DisposeBag()<br>let ageRelay = PublishRelay&lt;Int&gt;()<br>let nameRelay = PublishRelay&lt;String&gt;()<br>let userObservable = Observable.zip(nameRelay.asObservable(), ageRelay.asObservable())<br><br>userObservable.subscribe(onNext: { userName, age in<br>    print(&quot;Username: \(userName), Age: \(age)&quot;)<br>}).disposed(by: disposeBag)<br><br>nameRelay.accept(&quot;Ashwani&quot;)    // No output yet<br>ageRelay.accept(26)            // Output: Username: Ashwani, Age: 26<br>nameRelay.accept(&quot;Mayank&quot;)     // No output yet<br>ageRelay.accept(27)            // Output: Username: Mayank, Age: 27</pre><p>The above code is creating two instances of the PublishRelay class - ageRelay and nameRelay. These relays are used to emit Int and String values, respectively.</p><p>Then, it creates an observable userObservable using the zip operator to combine the emissions of nameRelay and ageRelay into a single observable. The zip operator emits a tuple of the most recently emitted values from each source observable whenever all the source observables have emitted at least one value.</p><p><strong>Working</strong> —</p><p>The first call to nameRelay.accept(&quot;Ashwani&quot;) does not produce any output because there is not yet an age value emitted from ageRelay, and zip waits until it has values from both observables before emitting a tuple of their values.</p><p>The next call to ageRelay.accept(26) triggers the userObservable to emit a tuple containing the latest values from both nameRelay and ageRelay. This tuple is then printed to the console as &quot;Username: Ashwani, Age: 26&quot;.</p><p>The third call to nameRelay.accept(&quot;Mayank&quot;) does not produce any output yet because there is not yet an age value emitted from ageRelay.</p><p>Finally, the fourth call to ageRelay.accept(27) triggers another emission from userObservable, this time with the latest values of &quot;Mayank&quot; from nameRelay and 27 from ageRelay. This tuple is then printed to the console as &quot;Username: Mayank, Age: 27&quot;.</p><h3><strong>Differences:</strong></h3><p>The main difference between these operators is the way they combine events from multiple observables.</p><p><strong>Merge</strong> simply merges events from all observables of same type in the order they are received, without combining them.</p><p><strong>CombineLatest</strong> combines the latest events from all observables every time any of them emits an event.</p><p><strong>Zip</strong> combines events from all observables only when all of them have emitted an event.</p><h3><strong>When to use each one:</strong></h3><p>Merge is useful when you want to simply merge multiple streams into a single stream without any transformation or combination. CombineLatest is useful when you want to combine the latest events from multiple observables into a single event. This is useful, for example, when you want to combine the latest values from multiple text fields in a form. Zip is useful when you want to combine events from multiple observables, but only when all of them have emitted an event. This is useful, for example, when you want to combine events from multiple buttons, but only when all of them are pressed.</p><p>In conclusion, Merge, combineLatest, and Zip are powerful operators in RxSwift that allow you to combine or merge multiple streams into a single stream. Understanding the differences between these operators and when to use each one will help you write more efficient and concise code.</p><p>I hope this helped out in clearing your doubts. You may follow me to read out such more interesting article on reactive programming or iOS.</p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2aff08049241" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Dynamic Custom Home Screen Quick Actions / Shortcuts for Your iOS Apps]]></title>
            <link>https://medium.com/@ashwani.cse4/create-dynamic-custom-home-screen-quick-actions-shortcuts-for-your-ios-apps-477f86423c6?source=rss-b4eff866468b------2</link>
            <guid isPermaLink="false">https://medium.com/p/477f86423c6</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ios-13]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Ashwani Kumar]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 14:47:47 GMT</pubDate>
            <atom:updated>2021-09-13T14:47:47.797Z</atom:updated>
            <content:encoded><![CDATA[<p>Home screen quick actions are a convenient way to perform useful, app-specific actions right from the Home screen. So probably you have noticed if you long pressed the app icon , some list of actions popped up for you. These actions are known as <strong>Home Screen Quick Actions.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*OjmEuUq_3fD9_WTjdfwkig.png" /><figcaption>Home Screen Shortcuts for Nestap application</figcaption></figure><p><strong>Concepts -</strong></p><ol><li>A Quick action can have Type(required),Title(required), Subtitle(optional) and an Icon(optional).</li><li>you can add as many as Quick Actions to your application but system will show them as per available spaces</li><li>For handling tap of the action we uses type of the quick action to identify the appropriate action.</li></ol><p>You can add these Quick Actions to your application using two ways.</p><ol><li><strong>Statically- </strong>adds Quick actions in info.plist ( we are not elaborating more on this)</li><li><strong>Dynamically</strong> — Dynamic quick actions depend on specific data or state of the app . Generally you can add Quick Action to the <strong>shortcutItem </strong>property of the shared <a href="https://developer.apple.com/documentation/uikit/uiapplication">UIApplication</a> instance to an array of <a href="https://developer.apple.com/documentation/uikit/uiapplicationshortcutitem">UIApplicationShortcutItem</a> objects , but it is suggested to set them when your application is going to the background state i.e <a href="https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622950-applicationwillresignactive">applicationWillResignActive(_:)</a> method.</li></ol><p>let’s get stick to our business and start implementing</p><ol><li>Hit CMD+SHIFT+N to create new Xcode iOS project and select Swift as programming language , Storyboard as designing interface and UIKit App Delegate as Application life cycle.</li><li>For convenient create a ShortcutHelper.swift file.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6e12b7c78a5dea2d2f113ba5b1ab88b/href">https://medium.com/media/a6e12b7c78a5dea2d2f113ba5b1ab88b/href</a></iframe><p>3. Now create function for preparing and adding Quick actions and handling taping of items in the same file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51500907e7421c05f307fa58c87d938e/href">https://medium.com/media/51500907e7421c05f307fa58c87d938e/href</a></iframe><p>This method prepare UIApplicationShortcutItems and adds them to shortcutItems property of <a href="https://developer.apple.com/documentation/uikit/uiapplication">UIApplication</a>.</p><p>4 . Now call this method inside <a href="https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622950-applicationwillresignactive">applicationWillResignActive(_:)</a> as apple suggests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c78db7265888bb2c96de553b357093f9/href">https://medium.com/media/c78db7265888bb2c96de553b357093f9/href</a></iframe><p>Now it’s time to handling tap actions of these shortcut.</p><p>There might be Two cases when Quick Action item tapped.</p><ol><li><strong>When app is not loaded yet.</strong></li></ol><p>If your app hasn’t been loaded before tapping the quick action, the following code within the scene delegate will be used to respond to the tapping.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6497e6da2071d31bf4fa683dc138c4ac/href">https://medium.com/media/6497e6da2071d31bf4fa683dc138c4ac/href</a></iframe><p>2.<strong> If App has been loaded</strong></p><p>in this case as soon as Quick action item is tapped , it fires up <a href="https://developer.apple.com/documentation/uikit/uiwindowscenedelegate/3238088-windowscene">windowScene(_:performActionFor:completionHandler:)</a>of SceneDelegate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e81fafa78868369419e27c9050916cd0/href">https://medium.com/media/e81fafa78868369419e27c9050916cd0/href</a></iframe><p>That’s it ……</p><p>I hope this worked for you , in case you have any problem do visit my git repository for this project</p><p><a href="https://github.com/ashwani280496/DynamicQuickAction.git">GitHub - ashwani280496/DynamicQuickAction: This is a sample app to elaborate how to add Quick actions in iOS Apps dynamically</a></p><h3><strong>References</strong></h3><ul><li><a href="https://developer.apple.com/documentation/uikit/menus_and_shortcuts/add_home_screen_quick_actions">Add Home Screen Quick Actions | Apple Developer Documentation</a></li><li><a href="https://developer.apple.com/design/human-interface-guidelines/ios/system-capabilities/home-screen-actions/">Home Screen Actions - System Capabilities - iOS - Human Interface Guidelines - Apple Developer</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=477f86423c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>