<?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 Nikola Grujic on Medium]]></title>
        <description><![CDATA[Stories by Nikola Grujic on Medium]]></description>
        <link>https://medium.com/@grujic.nikola91?source=rss-610fb4396e4d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YbC9yg9udPiBekUkW-6qeg.jpeg</url>
            <title>Stories by Nikola Grujic on Medium</title>
            <link>https://medium.com/@grujic.nikola91?source=rss-610fb4396e4d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 03:02:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@grujic.nikola91/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[Resize UIImage in Swift]]></title>
            <link>https://medium.com/@grujic.nikola91/resize-uiimage-in-swift-3e51f09f7a02?source=rss-610fb4396e4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e51f09f7a02</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Nikola Grujic]]></dc:creator>
            <pubDate>Wed, 27 Sep 2023 10:05:12 GMT</pubDate>
            <atom:updated>2023-09-27T10:05:12.984Z</atom:updated>
            <content:encoded><![CDATA[<p>Resizing UIImage is something that is often needed during the application development. It could be that the image needs to be resized before uploading or after downloading.</p><p>Fortunately, Apple made APIs that make it possible to resize images while preserving the aspect ratio.</p><p>Following extension of UIImage can be used to resize the image:</p><pre>import UIKit<br>import AVFoundation<br><br>public extension UIImage {<br>    /// Resize image while keeping the aspect ratio. Original image is not modified.<br>    /// - Parameters:<br>    ///   - width: A new width in pixels.<br>    ///   - height: A new height in pixels.<br>    /// - Returns: Resized image.<br>    func resize(_ width: Int, _ height: Int) -&gt; UIImage {<br>        // Keep aspect ratio<br>        let maxSize = CGSize(width: width, height: height)<br><br>        let availableRect = AVFoundation.AVMakeRect(<br>            aspectRatio: self.size,<br>            insideRect: .init(origin: .zero, size: maxSize)<br>        )<br>        let targetSize = availableRect.size<br><br>        // Set scale of renderer so that 1pt == 1px<br>        let format = UIGraphicsImageRendererFormat()<br>        format.scale = 1<br>        let renderer = UIGraphicsImageRenderer(size: targetSize, format: format)<br><br>        // Resize the image<br>        let resized = renderer.image { _ in<br>            self.draw(in: CGRect(origin: .zero, size: targetSize))<br>        }<br><br>        return resized<br>    }<br>}</pre><p>It can be used in the following way:</p><pre>let uiImage = UIImage(data: data)<br>let resizedImage = uiImage.resize(1500, 1500)</pre><p>Image object from SwiftUI can easily be instantiated from UIImage:</p><pre>let image = Image(uiImage: resizedImage)</pre><h3>Test</h3><p>It is practical to test the resizing function to confirm that the resulting image has the requested size and that the original image is unchanged.</p><p>For this test to work, it is necessary to add test .png image to the Resources of your project or to the swift package.</p><pre>import XCTest<br><br>final class UIImageExtensionsTests: XCTestCase {<br>    func testResize() {<br>        guard let path = Bundle.module.path(forResource: &quot;testImage&quot;, ofType: &quot;png&quot;),<br>            let image = UIImage(contentsOfFile: path)<br>        else {<br>            XCTFail(&quot;Failed to load image from Resources.&quot;)<br>            return<br>        }<br><br>        // Check original image<br>        XCTAssertEqual(image.size.width, 3024.0)<br>        XCTAssertEqual(image.size.height, 4032.0)<br><br>        // Check resized image<br>        let resizedImage = image.resize(1500, 1500)<br>        XCTAssertEqual(resizedImage.size.width, 1125.0)<br>        XCTAssertEqual(resizedImage.size.height, 1500.0)<br><br>        // Check that the original image is unchanged<br>        XCTAssertEqual(image.size.width, 3024.0)<br>        XCTAssertEqual(image.size.height, 4032.0)<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e51f09f7a02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Security basics part 5 — Anti-tampering]]></title>
            <link>https://medium.com/@grujic.nikola91/security-basics-part-5-anti-tampering-fefb32471d40?source=rss-610fb4396e4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fefb32471d40</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Nikola Grujic]]></dc:creator>
            <pubDate>Tue, 26 Sep 2023 09:08:15 GMT</pubDate>
            <atom:updated>2023-09-26T09:46:55.107Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Security basics part 5 — Anti-tampering</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*Yp31eU6mdlgmX_Te1RSfaA.png" /></figure><p>This article series covers a list of basic security measures that should be implemented in the process of iOS application development.</p><p>Security measures that should be applied during development depend on the nature of the application. High-risk applications that are processing personal, confidential or personal data should implement strict security mechanisms.</p><h3><strong>Anti-tampering</strong></h3><p>Using anti-tampering mechanisms brings an additional layer of security. This kind of protection is not bulletproof, but it may discourage attackers from tampering with the application.</p><p>For iOS there is an open source anti-tampering library, <a href="https://github.com/securing/IOSSecuritySuite">iOS Security Suit</a>.</p><p>This library allows for checking of following tampering attacks:</p><ol><li>Jailbreak device</li><li>Attached debugger</li><li>Running in emulator</li><li>Reverse engineering tools</li></ol><p>Library can be added to the project with Swift Package Manager:</p><pre>.package(url: &quot;https://github.com/securing/IOSSecuritySuite.git&quot;, from: &quot;1.9.9&quot;)</pre><p>After adding ISS to your project, you will also need to update your main Info.plist. There is a check in jailbreak detection module that uses canOpenURL(_:) method and requires specifying URLs that will be queried:</p><pre>&lt;key&gt;LSApplicationQueriesSchemes&lt;/key&gt;<br>&lt;array&gt;<br>    &lt;string&gt;undecimus&lt;/string&gt;<br>    &lt;string&gt;sileo&lt;/string&gt;<br>    &lt;string&gt;zbra&lt;/string&gt;<br>    &lt;string&gt;filza&lt;/string&gt;<br>    &lt;string&gt;activator&lt;/string&gt;<br>&lt;/array&gt;</pre><p>First step is to create specialized error class that will contain detailed explanation of security warnings:</p><pre>import Foundation<br><br>public final class SecurityError: Error {<br>    public enum SecurityErrorType {<br>        case jailbroken(failMessage: String)<br>        case debugged<br>        case emulator<br>        case reverseEngineered(failMessage: String)<br>        case proxied<br>    }<br><br>    let errorType: SecurityErrorType<br><br>    public init(_ errorType: SecurityErrorType) {<br>        self.errorType = errorType<br>    }<br>}<br><br>extension SecurityError: LocalizedError {<br>    public var errorDescription: String? {<br>        switch errorType {<br>        case .jailbroken:<br>            return &quot;Jailbroken device.&quot;<br>        case .debugged:<br>            return &quot;Debugger detected.&quot;<br>        case .emulator:<br>            return &quot;Running in emulator.&quot;<br>        case .reverseEngineered:<br>            return &quot;Reverse engineering tools detected.&quot;<br>        case .proxied:<br>            return &quot;Proxy detected.&quot;<br>        }<br>    }<br><br>    public var failureReason: String? {<br>        switch errorType {<br>        case let .jailbroken(failMessage):<br>            return failMessage<br>        case .debugged:<br>            return &quot;Application seems to be debugged.&quot;<br>        case .emulator:<br>            return &quot;Application seems to be running in emulator.&quot;<br>        case let .reverseEngineered(failMessage):<br>            return failMessage<br>        case .proxied:<br>            return &quot;Application seems to be proxied.&quot;<br>        }<br>    }<br><br>    public var recoverySuggestion: String? {<br>        switch errorType {<br>        case .jailbroken:<br>            return &quot;Run on a device that is not jailbroken.&quot;<br>        case .debugged:<br>            return &quot;Stop debugging.&quot;<br>        case .emulator:<br>            return &quot;Stop running in the emulator.&quot;<br>        case .reverseEngineered:<br>            return &quot;Stop running reverse engineering tools.&quot;<br>        case .proxied:<br>            return &quot;Stop running via proxy.&quot;<br>        }<br>    }<br>}</pre><p>In the second step, a security protocol is implemented. It contains only one function that returns Result object. It is recommended to return Result object instead of a simple boolean, since the boolean value can easily be replaced.</p><pre>public protocol SecurityProtocol: AnyObject {<br>    func isSafeEnvironment() -&gt; Result&lt;String, Error&gt;<br>}</pre><p>In the third step, a class that conforms to the SecurityProtocol is implemented.</p><pre>import Foundation<br>import IOSSecuritySuite<br><br>class Security: SecurityProtocol {<br>    // MARK: - SecurityProtocol<br>    func isSafeEnvironment() -&gt; Result&lt;String, Error&gt; {<br>        let jailbreakStatus = IOSSecuritySuite.amIJailbrokenWithFailMessage()<br><br>        if jailbreakStatus.jailbroken {<br>            return .failure(SecurityError(.jailbroken(failMessage: jailbreakStatus.failMessage)))<br>        }<br><br>        if IOSSecuritySuite.amIDebugged() {<br>            return .failure(SecurityError(.debugged))<br>        }<br><br>        if IOSSecuritySuite.amIRunInEmulator() {<br>            return .failure(SecurityError(.emulator))<br>        }<br><br>        let reverseStatus = IOSSecuritySuite.amIReverseEngineeredWithFailedChecks()<br>        if reverseStatus.reverseEngineered {<br>            let failMessage = reverseStatus.failedChecks.map { $0.failMessage }.description<br>            return .failure(SecurityError(.reverseEngineered(failMessage: failMessage)))<br>        }<br><br>        if IOSSecuritySuite.amIProxied() {<br>            return .failure(SecurityError(.proxied))<br>        }<br><br>        return .success(&quot;Safe environment.&quot;)<br>    }<br>}</pre><p>In the fourth and final step, security check should be performed in the root application view. In case of an unsafe environment detection, a warning will be displayed with an error message.</p><pre>import SwiftUI<br><br>@main<br>struct MyApp: App {<br>    private var security: SecurityProtocol = Security()<br>    @State private var safeEnvironment = true<br>    @State private var failMessage: String = &quot;&quot;<br><br>    var body: some Scene {<br>        WindowGroup {<br>            if safeEnvironment {<br>                ContentView()<br>                .onAppear {<br>                    isSafeEnvironment()<br>                }<br>            } else {<br>                Text(failMessage)<br>            }<br>        }<br>    }<br><br>    private func isSafeEnvironment() {<br>        #if DEBUG<br>        safeEnvironment = true<br>        #else<br>        let result = security.isSafeEnvironment()<br>        switch result {<br>        case .success:<br>            safeEnvironment = true<br>        case .failure(let error):<br>            safeEnvironment = false<br><br>            guard let securityError = error as? SecurityError else {<br>                return<br>            }<br><br>            failMessage = &quot;Unsafe environment detected.\n\(securityError.errorDescription ?? &quot;&quot;)&quot;<br>        }<br>        #endif<br>    }<br>}</pre><p>You might also be interested in the following articles…</p><ul><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-1-turn-off-javascript-in-wkwebview-55f1034ba45f">Security basics part 1 — Turn off JavaScript in WKWebView</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-2-clear-cache-in-wkwebview-d2a988b8cfba">Security basics part 2 — Clear cache in WKWebView</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-3-disable-autocorrection-95cba9da9e4b">Security basics part 3 — Disable Autocorrection</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-4-prevent-screen-capture-ff01d588c3ae">Security basics part 4 — Prevent screen capture</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fefb32471d40" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Security basics part 4 — Prevent screen capture]]></title>
            <link>https://medium.com/@grujic.nikola91/security-basics-part-4-prevent-screen-capture-ff01d588c3ae?source=rss-610fb4396e4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff01d588c3ae</guid>
            <category><![CDATA[swif]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Nikola Grujic]]></dc:creator>
            <pubDate>Tue, 26 Sep 2023 08:42:01 GMT</pubDate>
            <atom:updated>2023-09-26T09:46:12.125Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Security basics part 4 — Prevent screen capture</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*Yp31eU6mdlgmX_Te1RSfaA.png" /></figure><p>This article series covers a list of basic security measures that should be implemented in the process of iOS application development.</p><p>Security measures that should be applied during development depend on the nature of the application. High-risk applications that are processing personal, confidential or personal data should implement strict security mechanisms.</p><h3><strong>Prevent screen capture</strong></h3><p>The system automatically preserves the screen capture on iOS when the application moves to the background. This is a potential risk if the user is on the screen with sensitive data and does not close the application completely. It is possible to take screenshot of the screen with sensitive data by just browsing the background applications.</p><p>First step is recognising when is the application changing state. This can be achieved by implementing extension function for View in SwiftUI:</p><pre>import SwiftUI<br><br>public extension View {<br>    func willEnterForeground(perform action: @escaping () -&gt; Void) -&gt; some View {<br>        self.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in<br>            action()<br>        }<br>    }<br><br>    func didBecomeActive(perform action: @escaping () -&gt; Void) -&gt; some View {<br>        self.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in<br>            action()<br>        }<br>    }<br><br>    func willResignActive(perform action: @escaping () -&gt; Void) -&gt; some View {<br>        self.onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)) { _ in<br>            action()<br>        }<br>    }<br><br>    func didEnterBackground(perform action: @escaping () -&gt; Void) -&gt; some View {<br>        self.onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in<br>            action()<br>        }<br>    }<br>}</pre><p>Second step is creating a protection view that will be displayed when the application moves to background:</p><pre>import SwiftUI<br><br>public struct ProtectionView: View {<br>    public var body: some View {<br>        Text(&quot;Protection view&quot;)<br>    }<br>}<br><br>#Preview {<br>    ProtectionView()<br>}</pre><p>In the third and final step, application state changes should be monitored in the root application view. Protection view should be displayed once the application is moved to the background.</p><pre>import SwiftUI<br><br>@main<br>struct MyApp: App {<br>    @State private var appActive = true<br><br>    var body: some Scene {<br>        WindowGroup {<br>            if appActive {<br>                ContentView()<br>                    .willResignActive {<br>                        appActive = false<br>                    }<br>                    .didEnterBackground {<br>                        appActive = false<br>                    }<br>            } else {<br>                ProtectionView()<br>                .willEnterForeground {<br>                    appActive = true<br>                }<br>                .didBecomeActive {<br>                    appActive = true<br>                }<br>            }<br>        }<br>    }<br>}</pre><p>You might also be interested in the following articles…</p><ul><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-1-turn-off-javascript-in-wkwebview-55f1034ba45f">Security basics part 1 — Turn off JavaScript in WKWebView</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-2-clear-cache-in-wkwebview-d2a988b8cfba">Security basics part 2 — Clear cache in WKWebView</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-3-disable-autocorrection-95cba9da9e4b">Security basics part 3 — Disable Autocorrection</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-5-anti-tampering-fefb32471d40">Security basics part 5 — Anti-tampering</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff01d588c3ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Security basics part 3 — Disable Autocorrection]]></title>
            <link>https://medium.com/@grujic.nikola91/security-basics-part-3-disable-autocorrection-95cba9da9e4b?source=rss-610fb4396e4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/95cba9da9e4b</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Nikola Grujic]]></dc:creator>
            <pubDate>Tue, 26 Sep 2023 07:38:45 GMT</pubDate>
            <atom:updated>2023-09-30T19:29:52.440Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Security basics part 3 — Disable Autocorrection on TextField</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*Yp31eU6mdlgmX_Te1RSfaA.png" /></figure><p>This article series covers a list of basic security measures that should be implemented in the process of iOS application development.</p><p>Security measures that should be applied during development depend on the nature of the application. High-risk applications that are processing personal, confidential or personal data should implement strict security mechanisms.</p><h3><strong>Disable Autocorrection</strong></h3><p>In critical functionalities, like password fields or some other fields that contains sensitive data, be careful when setting up the keyboard, because it can save keystrokes in the cache. It can also save the phrases used for password and propose them in autocorrect suggestions.</p><p>Autocorrection can easily be disabled on TextField in SwiftUI:</p><pre>TextField(&quot;Password&quot;, text: $text) { editingChanged in<br>    print(&quot;action&quot;)<br>}<br>.disableAutocorrection(true)</pre><p>You might also be interested in the following articles…</p><ul><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-1-turn-off-javascript-in-wkwebview-55f1034ba45f">Security basics part 1 — Turn off JavaScript in WKWebView</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-2-clear-cache-in-wkwebview-d2a988b8cfba">Security basics part 2 — Clear cache in WKWebView</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-4-prevent-screen-capture-ff01d588c3ae">Security basics part 4 — Prevent screen capture</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-5-anti-tampering-fefb32471d40">Security basics part 5 — Anti-tampering</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95cba9da9e4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Security basics part 2 — Clear cache in WKWebView]]></title>
            <link>https://medium.com/@grujic.nikola91/security-basics-part-2-clear-cache-in-wkwebview-d2a988b8cfba?source=rss-610fb4396e4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2a988b8cfba</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Nikola Grujic]]></dc:creator>
            <pubDate>Tue, 26 Sep 2023 07:37:01 GMT</pubDate>
            <atom:updated>2023-09-26T09:44:04.790Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Security basics part 2 — Clear cache in WKWebView</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*Yp31eU6mdlgmX_Te1RSfaA.png" /></figure><p>This article series covers a list of basic security measures that should be implemented in the process of iOS application development.</p><p>Security measures that should be applied during development depend on the nature of the application. High-risk applications that are processing personal, confidential or personal data should implement strict security mechanisms.</p><h3><strong>Clear cache in WKWebView</strong></h3><p>Sometimes the content of HTTPS pages or cookies can be stored by default in the local web browser cache. This behaviour also brings various security risks.</p><p>In order to reduce security risks, it is recommended to clear cookies and cache of WKWebView.</p><p>This can be achieved by implementing a simple extension functions:</p><pre>public extension WKWebView {<br>    static func clearCookies() {<br>        HTTPCookieStorage.shared.removeCookies(since: Date.distantPast)<br>    }<br><br>    static func clearCache(displayName: String) {<br>        DispatchQueue.main.async {<br>            WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in<br>                for record in records where record.displayName.contains(displayName) {<br>                    WKWebsiteDataStore.default().removeData(<br>                        ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(),<br>                        for: [record]<br>                    ) {}<br>                }<br>            }<br>        }<br>    }<br>}</pre><p>These static functions can than be called directly on WKWebView when needed:</p><pre>WKWebView.clearCookies()<br>WKWebView.clearCache()</pre><p>You might also be interested in the following articles…</p><ul><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-1-turn-off-javascript-in-wkwebview-55f1034ba45f">Security basics part 1 — Turn off JavaScript in WKWebView</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-3-disable-autocorrection-95cba9da9e4b">Security basics part 3 — Disable Autocorrection</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-4-prevent-screen-capture-ff01d588c3ae">Security basics part 4 — Prevent screen capture</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-5-anti-tampering-fefb32471d40">Security basics part 5 — Anti-tampering</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2a988b8cfba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Security basics part 1 — Turn off JavaScript in WKWebView]]></title>
            <link>https://medium.com/@grujic.nikola91/security-basics-part-1-turn-off-javascript-in-wkwebview-55f1034ba45f?source=rss-610fb4396e4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/55f1034ba45f</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Nikola Grujic]]></dc:creator>
            <pubDate>Tue, 26 Sep 2023 07:33:17 GMT</pubDate>
            <atom:updated>2023-09-26T09:10:05.166Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Security basics part 1 — Turn off JavaScript in WKWebView</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*Yp31eU6mdlgmX_Te1RSfaA.png" /></figure><p>This article series covers a list of basic security measures that should be implemented in the process of iOS application development.</p><p>Security measures that should be applied during development depend on the nature of the application. High-risk applications that are processing personal, confidential or personal data should implement strict security mechanisms.</p><h3><strong>Turn off JavaScript in WKWebView</strong></h3><p>Some applications need to use browser components. Using browser components is less secure, they bring various risks and expose the application to attacks via known vulnerabilities in browser engines.</p><p>In iOS applications it is recommended to use WKWebView, which is more secure than deprecated UIWebView.</p><p>Even when WKWebView is used, if JavaScript is not necessary, it should be disabled. It can be disabled using this code:</p><pre>let webview = WKWebView()<br>webview.configuration.defaultWebpagePreferences.allowsContentJavaScript = false</pre><p>You might also be interested in the following articles…</p><ul><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-2-clear-cache-in-wkwebview-d2a988b8cfba">Security basics part 2 — Clear cache in WKWebView</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-3-disable-autocorrection-95cba9da9e4b">Security basics part 3 — Disable Autocorrection</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-4-prevent-screen-capture-ff01d588c3ae">Security basics part 4 — Prevent screen capture</a></li><li><a href="https://medium.com/@grujic.nikola91/security-basics-part-5-anti-tampering-fefb32471d40">Security basics part 5 — Anti-tampering</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55f1034ba45f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to check for network connection in SwiftUI using NWPathMonitor]]></title>
            <link>https://medium.com/@grujic.nikola91/how-to-check-for-network-connection-in-swiftui-using-nwpathmonitor-a2eb2e508ea8?source=rss-610fb4396e4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2eb2e508ea8</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios-17]]></category>
            <dc:creator><![CDATA[Nikola Grujic]]></dc:creator>
            <pubDate>Sun, 24 Sep 2023 13:05:05 GMT</pubDate>
            <atom:updated>2023-09-24T13:05:05.594Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>NetworkMonitor</strong></h3><p>In order to check for any changes in the network connectivity, <strong>NWPathMonitor</strong> class can be used. It is provided by Apple as a part of Network framework.</p><p>With the introduction of <strong>@Observable</strong> macro in Swift 5.9, <strong>NetworkMonitor</strong> class can be implemented using the following code:</p><pre>import Foundation<br>import Network<br><br>@Observable<br>class NetworkMonitor {<br>    private let networkMonitor = NWPathMonitor()<br>    private let workerQueue = DispatchQueue(label: &quot;Monitor&quot;)<br>    var isConnected = false<br><br>    init() {<br>        networkMonitor.pathUpdateHandler = { path in<br>            self.isConnected = path.status == .satisfied<br>        }<br>        networkMonitor.start(queue: workerQueue)<br>    }<br>}</pre><p>First property is an <strong>NWPathMonitor</strong> observer, second property is a <strong>DispatchQueue</strong> where the monitor does its work. Third property is a bool value which will be tracked in the view in order to react on the changes in network connectivity.</p><p><strong>NWPathMonitor</strong> is initialized without parameters, which means it will observe all connection types (wifi, celullar, wired ethernet and other).</p><h3><strong>Network unavailable view</strong></h3><p>With iOS 17, a new view for empty state was introduced, <a href="https://developer.apple.com/documentation/swiftui/contentunavailableview">ContentUnavailableView</a></p><p>This new view can be conveniently used to create a warning view for a network connection error.</p><pre>import SwiftUI<br><br>struct NetworkUnavailableView: View {<br>    var body: some View {<br>        ContentUnavailableView(<br>            &quot;No Internet Connection&quot;,<br>            systemImage: &quot;wifi.exclamationmark&quot;,<br>            description: Text(&quot;Please check your connection and try again.&quot;)<br>        )<br>    }<br>}<br><br>#Preview {<br>    NetworkUnavailableView()<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*8RT-h4wUTaK2qd8ZFYueTw.png" /><figcaption>Network unavailable view</figcaption></figure><h3>Update UI</h3><p>In order to use <strong>NetworkMonitor </strong>and update the view, <strong>NetworkMonitor</strong> has to be instantiated as a @<strong>State.</strong> Changes in the connection will update the value of <strong>isConnected</strong> flag and update the view. It can be implemented using this code:</p><pre>struct ContentView: View {<br>    @State private var networkMonitor = NetworkMonitor()<br><br>    var body: some View {<br>        if networkMonitor.isConnected {<br>            Text(&quot;Internet Connection available&quot;)<br>        } else {<br>            ContentUnavailableView(<br>                &quot;No Internet Connection&quot;,<br>                systemImage: &quot;wifi.exclamationmark&quot;,<br>                description: Text(&quot;Please check your connection and try again.&quot;)<br>            )<br>        }<br>    }<br>}</pre><p>Alternatively, <strong>NetworkMonitor</strong> can be injected as an environment object and used across the app.</p><pre>@main<br>struct MyApp: App {<br>    @State private var networkMonitor = NetworkMonitor()<br><br>    var body: some Scene {<br>        WindowGroup {<br>            ContentView()<br>                .environmentObject(networkMonitor)<br>        }<br>    }<br>}<br><br>struct ContentView: View {<br>    @Environment(NetworkMonitor.self) private var networkMonitor<br><br>    var body: some View {<br>        if networkMonitor.isConnected {<br>            Text(&quot;Internet Connection available&quot;)<br>        } else {<br>            ContentUnavailableView(<br>                &quot;No Internet Connection&quot;,<br>                systemImage: &quot;wifi.exclamationmark&quot;,<br>                description: Text(&quot;Please check your connection and try again.&quot;)<br>            )<br>        }<br>    }<br>}</pre><h3>Testing</h3><p>Network connection changes are not detected consistently in the Simulator, the suggestion is to perform testing on a real device.</p><h3><strong>Inspired by</strong></h3><ul><li><a href="https://www.danijelavrzan.com/posts/2022/11/network-connection-alert-swiftui/">How to check for network connection and present an alert in SwiftUI | Danijela&#39;s blog</a></li><li><a href="https://sarunw.com/posts/content-unavailable-view-in-swiftui/">ContentUnavailableView in SwiftUI | Sarunw</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2eb2e508ea8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>