<?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 Shubham Jain on Medium]]></title>
        <description><![CDATA[Stories by Shubham Jain on Medium]]></description>
        <link>https://medium.com/@zenshubham09?source=rss-85c3f69e9ab4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XFCKuK7CYv_GEhh8.</url>
            <title>Stories by Shubham Jain on Medium</title>
            <link>https://medium.com/@zenshubham09?source=rss-85c3f69e9ab4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 07:13:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zenshubham09/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[Configure flutter with android studio and VS Code]]></title>
            <link>https://zenshubham09.medium.com/configure-flutter-with-android-studio-and-vs-code-70f22a96fb1?source=rss-85c3f69e9ab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/70f22a96fb1</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Shubham Jain]]></dc:creator>
            <pubDate>Mon, 20 Apr 2020 08:39:50 GMT</pubDate>
            <atom:updated>2020-04-20T08:39:50.777Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Today</strong>, we will see How To Install Flutter On Mac, user can also install flutter on windows as well. Flutter allows us to make build beautiful native apps on iOS, Android and web from the single codebase. Flutter’s widget architecture incorporates all the critical platform differences such as scrolling, navigation, icons and fonts to provide full native performance on iOS ,Android and web devices.</blockquote><p>Flutter’s <em>hot reload</em> helps us quickly and easily experiment, build UIs, add features, and fix bugs faster.<br> Experience sub-second reload times, without losing the state, on emulators, simulators, and hardware for iOS and Android.</p><p>Flutter’s built-in beautiful Material design and Cupertino design (iOS ) widgets, rich motion APIs, smooth, natural scrolling, and platform awareness</p><p>Lets start with configuration process</p><h3>Prerequisites:</h3><ol><li><strong>Operating Systems</strong>: macOS (64-bit)</li><li><strong>Disk Space</strong>: 2.8 GB (does not include disk space for IDE/tools)</li><li><strong>Tools</strong>: Flutter depends on these command-line tools being available in your environment <br>bash ,curl, git2.x, mkdir, rm, unzip, which, zip</li></ol><h4>Get Flutter SDK for mac:</h4><ol><li>User can download the flutter sdk stable version using the below command<br><a href="https://storage.googleapis.com/flutter_infra/releases/stable/macos/flutter_macos_v1.12.13+hotfix.9-stable.zip">https://storage.googleapis.com/flutter_infra/releases/stable/macos/flutter_macos_v1.12.13+hotfix.9-stable.zip</a></li><li>After downloading the zip file extract zip file at any desired location using the following command on terminal <br>$ cd ~/development<br>$ unzip ~/Downloads/flutter_macos_v1.12.13+hotfix.9-stable.zip</li><li>User can also clone the latest version of SDK <br>$ git clone https://github.com/flutter/flutter.git -b stable</li><li>Add the flutter tool to your path<br>$ export PATH<strong>=</strong>&quot;$PATH:`pwd`/flutter/bin</li><li>If user want to update the path, user can do it using<br>$ export PATH<strong>=</strong>&quot;$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin&quot;</li><li>User can also verify path that is configured<br>$ echo $PATH</li></ol><h3>Plateform setup:</h3><h4>iOS Configuration</h4><ol><li>Install Xcode</li></ol><blockquote>If you have multiple xcode then set the default xcode path<br>$ sudo xcode-select --switch/Applications/Xcode.app/Contents/Developer</blockquote><p>2. User can create first flutter application using terminal <br>$ flutter create appName(myApp)</p><p>3. Launch the application using this<br>$ flutter run</p><h4>Android Configuration</h4><ol><li>Install the android studio.</li><li>While creating a new flutter project user need to set the package name/ bundle identifier of the application.</li><li>User also need to set flutter SDK path as well. User need to provide the <strong><em>project name is lowercase</em></strong> as it is the convention that flutter use.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o6xkkJ49CIdtMJeZPM-SwA.png" /></figure><ol><li>Go to android studio preferences and select plugins option then install flutter and dart plugins.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AA0C7WKY8bzswtvKF-PSJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oSGvY-L35UkYxSPt37QysA.png" /></figure><p><strong>Setup Android Device</strong></p><ol><li>First to enable the developer option in your device</li><li>Then , go to developer option and enable the USB Debugging option</li><li>Select your device in android studio</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KBUAYiSCAB0GSzAr-IdI8w.png" /></figure><blockquote>for web app select the chrome(web) option and simply launch the application. You do not need to do anything if you create new flutter project. <br>There should at-least one browser installed in your computer</blockquote><blockquote>After setting up android studio with required plugins and flutter SDK path, user can start with flutter demo application.<br><em>Note: User can also use VS Code for flutter instead of android studio.</em></blockquote><p><strong>Previous Post</strong>: Offline data storage<br> <a href="https://medium.com/@zenshubham09/offline-data-storage-in-ios-3e8dc68f6e3b">https://medium.com/@zenshubham09/offline-data-storage-in-ios-3e8dc68f6e3b</a></p><h4>Thanks</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70f22a96fb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Offline data storage in iOS]]></title>
            <link>https://zenshubham09.medium.com/offline-data-storage-in-ios-3e8dc68f6e3b?source=rss-85c3f69e9ab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e8dc68f6e3b</guid>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[internet-of-things]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Shubham Jain]]></dc:creator>
            <pubDate>Tue, 17 Apr 2018 18:38:26 GMT</pubDate>
            <atom:updated>2018-04-17T18:48:37.372Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://plus.google.com/103521365322037986439">+ShUBHAm JAin</a></h3><p>In this blog we will discuss<strong> offline / local iOS data storage</strong> guidelines for iOS apps intended to keep certain information locally. Local storage is meant for retaining web app data locally using certain frameworks, tools and methods distinctive to different platforms. For <em>iOS storage</em> there are different methods to choose from. The choice, however, depends upon what and how much data you want to store. Most of the times more than one method is required to implement local storage in iOS apps, as there are different persistence needs of the application viz. data gathered from web browsing, user preferences, and application settings. The most widely used methods for local storage implementation in iOS are:</p><ul><li>SQLite</li><li>Property List</li><li>Core Data</li><li>NSUser Defaults</li><li>Key Chain</li></ul><p>Different methods serve different data persistence purposes, for example, SQLite is used for low-level relational database work while Core Data is a modeling framework for object oriented Cocoa Touch Applications.</p><h2>Guidelines for Local iOS Applications Data Storage</h2><p><strong>SQLite For iOS Local Data Storage<br></strong>SQLite is a powerful lightweight C library that is embedded in an iOS application. This is used in various applications across various platforms including Android and iOS. It uses SQL-centric API to operate the data tables directly. Using SQLite C library for offline or local data storage implementation in iOS applications, user needs to be very meticulous when passing in strings and arguments required for the functions. SQLite is very particular about the argument type given to functions.</p><p><strong>Property List<br></strong>Next most common used method of offline storing data in iOS application is in Property List files. Documents in property list contain either an <strong>NSDictionary</strong> or an <strong>NSArray</strong>, inside which there is archived data.<br> There are number of classes that can be archived into the PList, eg. NSArray, NSDate, NSString, NSDictionary and NSdictionary. Objects other than these cannot be archived as a property list and will not be able to write the file. <br>user has to be very particular about listing items into the classes, for instance to store a Boolean or Integer object only NSNumber class is used. Boolean or Integer object must not be given to any objects in NSDictionary or NSArray.</p><p><strong>Core Data<br></strong>Core Data is the method recommended by Apple for local storage of app’s data. By default, core data uses SQLite as its main database in the iOS app. <br>Internally Core Data make use of SQLite queries to save and store its data locally, which is why all the files are stored as<strong> .db </strong>files. <br>This also eliminates the need to install a separate database. In iOS this framework allows for two different database storage types but by default it is SQLite.<br>Core Data allows you deal with common functionalities of an app like, <strong>restore</strong>, <strong>store</strong>, <strong>undo</strong> and <strong>redo</strong>.</p><p>Core data is a data modelling framework built on the model-view-controller(MVC) pattern. It is expressed in terms of entities and relationships. We can create entities and add relationships in the graphical form. This helps to eliminate most of the basic code and can be easily added into your application.</p><p>Core data provides an API to deal with common functionalities such as Save, Delete, Undo etc. which allows us to build applications easily. Using this we need not worry about SQL query and its syntax</p><p><strong>NSUserDefaults :<br></strong>To save properties in any application and user preferences, NSUserDefaults is one of the most common methods for local data storage. This is used to save logged in state of the user within an application, so that the app can fetch this data even when user access the application at some other time. In some of the iOS apps this method is used to save user’s confidential information like access token.</p><p>NSUserDefault is used to store small amounts of data. It allows the application to set and get its preferences and also allows the user to store it in a file. The stored values can be accessed globally within the whole application.</p><p>NSUserDefault caches the information. This helps the user avoid opening default databases, each time for default values.</p><blockquote><em>How to store data in user preference</em></blockquote><pre>NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];</pre><pre>[standardUserDefaults setObject:@”zenshubham09@blogspot.in” forKey:@”iOSBlogger”]; [standardUserDefaults synchronize];</pre><blockquote><em>How to fetch data from user preference</em></blockquote><pre>NSString *blogName = [standardUserDefaults objectForKey:@”iOSBlogger”];</pre><p><strong>Key Chain :</strong></p><p>Most of the time developers avoid implementing key chain method to save data as this method follows a complicated procedure. <br>If the device is<strong> jail broken</strong>, none of your data is secure. This is the most secure and reliable method to store data on a<strong> non-jailbroken device</strong>.<br>Simple wrapper classes are used to store data using key chain method. The code for saving data is similar to the code for saving data in NUserDefaults and the syntax used is very similar to that of NUserDefaults.</p><p>Using these methods developers can also reduce the vulnerabilities of iOS applications, by storing local data in a secure manner.<br>However, data storage using the keychain is not possible for a jailbroken device, where the attacker can access everything from PList files, key chain and other method implementations.</p><p>Using the methods listed above developers can make it tricky for attackers to reach the locally stored information. Also, iOS local storage increases the offline capabilities of a mobile application, thus making it less internet dependent.</p><p><strong><em>Note :</em></strong> Core data is a data modeling framework for object-oriented Cocoa touch applications, while SQLite is a low-level relational database and NSUserDefaults is a quick and easy way to store small amounts of data.</p><p><strong><em>Thanks</em></strong></p><p><strong>Previous Post : </strong>iOS interview Question<br><a href="https://medium.com/@zenshubham09/ios-interview-question-2af44bc7e748">https://medium.com/@zenshubham09/ios-interview-question-2af44bc7e748</a></p><p><strong>iOSBlogger : </strong><br><a href="https://zenshubham09.blogspot.in/2018/04/offline-data-storage-in-ios.html">https://zenshubham09.blogspot.in/2018/04/offline-data-storage-in-ios.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e8dc68f6e3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS Interview Question]]></title>
            <link>https://zenshubham09.medium.com/ios-interview-question-2af44bc7e748?source=rss-85c3f69e9ab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2af44bc7e748</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Shubham Jain]]></dc:creator>
            <pubDate>Thu, 29 Mar 2018 08:47:46 GMT</pubDate>
            <atom:updated>2018-04-12T18:47:37.440Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Question : Why is design pattern very important ? <br>Answer :</strong> Design patterns are reusable solutions to common problems in software design. They’re templates designed to help you write code that’s easy to understand and reuse. Most common Cocoa design patterns:</p><ul><li><strong>Creational</strong>: Singleton.</li><li><strong>Structural</strong>: Decorator, Adapter, Facade.</li><li><strong>Behavioral</strong>: Observer, and, Memento</li></ul><p><strong>Question: What is Singleton Pattern ? <br>Answer :</strong> The Singleton design pattern ensures that only one instance exists for a given class and that there’s a global access point to that instance. It usually uses lazy loading to create the single instance when it’s needed the first time.</p><p><strong>Question : What is Facade Design Pattern ? <br></strong>Answer : The Facade design pattern provides a single interface to a complex subsystem. Instead of exposing the user to a set of classes and their APIs, you only expose one simple unified API.</p><p><strong>Question : What is Decorator Design pattern ? <br>Answer</strong> : The Decorator pattern dynamically adds behaviors and responsibilities to an object without modifying its code. It’s an alternative to subclassing where you modify a class’s behavior by wrapping it with another object.</p><p>In Objective-C there are two <em>very</em> common implementations of this pattern: <a href="https://www.raywenderlich.com/46988/ios-design-patterns"><strong>Category</strong></a> and <a href="https://www.raywenderlich.com/46988/ios-design-patterns"><strong>Delegation</strong></a>. In Swift there are also two <em>very</em> common implementations of this pattern: <a href="https://www.raywenderlich.com/160651/design-patterns-ios-using-swift-part-12"><strong>Extensions</strong></a> and <a href="https://www.raywenderlich.com/160651/design-patterns-ios-using-swift-part-12"><strong>Delegation</strong></a>.</p><p><strong>Question : What is Adapter design pattern ? <br>Answer</strong> : An Adapter allows classes with incompatible interfaces to work together. It wraps itself around an object and exposes a standard interface to interact with that object.</p><p><strong>Question : What is Observer design pattern ? <br>Answer :</strong> In the Observer pattern, one object notifies other objects of any state changes.</p><p>Cocoa implements the observer pattern in two ways: <strong>Notifications</strong> and <strong>Key-Value Observing (KVO)</strong>.</p><p><strong>Question : What is Memento design pattern ? <br>Answer :</strong> In Memento Pattern saves your stuff somewhere. Later on, this externalized state can be restored without violating encapsulation; that is, private data remains private. One of Apple’s specialized implementations of the Memento pattern is Archiving other hand iOS uses the Memento pattern as part of <strong>State Restoration.</strong></p><p><strong>Question: Explain MVC design pattern ?</strong></p><ul><li><strong>Models</strong> — responsible for the domain data or a data access layer which manipulates the data, think of ‘Person’ or ‘PersonDataProvider’ classes.</li><li><strong>Views</strong> — responsible for the presentation layer (GUI), for iOS environment think of everything starting with ‘UI’ prefix.</li><li><strong>Controller/Presenter/ViewModel </strong>— the glue or the mediator between the Model and the View, in general responsible for altering the Model by reacting to the user’s actions performed on the View and updating the View with changes from the Model.</li></ul><p><strong>Question : Explain MVVM design pattern ?<br></strong>Answer : UIKit independent representation of your View and its state. The View Model invokes changes in the Model and updates itself with the updated Model, and since we have a binding between the View and the View Model, the first is updated accordingly.</p><p>Your view model will actually take in your model, and it can format the information that’s going to be displayed on your view.</p><p>There is a more known framework called <a href="https://github.com/ReactiveX/RxSwift?utm_source=swifting.io&amp;utm_medium=web&amp;utm_campaign=blog%20post">RxSwift</a>. It contains RxCocoa, which are reactive extensions for Cocoa and CocoaTouch.</p><p><strong>Question</strong> : <strong>What is Regular expressions ? <br>Answer</strong> : Regular expressions are special string patterns that describe how to search through a string.</p><p><strong>Question : What’s the difference between the frame and the bounds? <br>Answer</strong> : The bounds of an UIView is the rectangle expressed as a location (x,y) and size (width,height) relative to its own coordinate system (x=0,y = 0). <br>The frame of an UIView is the rectangle expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.</p><p><strong>Question : What is the difference strong, weak, read only and copy ?Answer: </strong>strong, weak, assign property attributes define how memory for that property will be managed.</p><p><strong>Strong</strong> means that the reference count will be increased and<br>the reference to it will be maintained through the life of the object</p><p><strong>Weak</strong>, means that we are pointing to an object but not increasing its reference count. It’s often used when creating a parent child relationship. The parent has a strong reference to the child but the child only has a weak reference to the parent.</p><p><strong>Read only</strong>, we can set the property initially but then it can’t be changed.</p><p><strong>Copy</strong>, means that we’re copying the value of the object when it’s created. Also prevents its value from changing.</p><p><strong>Question</strong> : <strong>What’s the difference between a xib and a storyboard?<br>Answer</strong> : Both are used in Xcode to layout screens /view controllers. A <strong>xib</strong> defines a single View or View Controller screen, while a <strong>storyboard</strong> shows many view controllers and also shows the relationship between them.</p><p><strong>Question </strong>: <strong>What is Xcode Bot?<br>Answer</strong> : Xcode Server uses bots to automatically build your projects. A bot represents a single remote repository, project, and scheme. We can also control the build configuration the bot uses and choose which devices and simulators the bot will use.</p><p><strong>Question :Explain Sequence in Swift<br></strong>Answer : Sequence is a basic type in Swift for defining an aggregation of elements that distribute sequentially in a row. <br>All collection types inherit from Sequence such as <strong>Array</strong>, <strong>Set</strong>, <strong>Dictionary</strong>.</p><p><strong>Question : What is the difference between KVO and </strong><strong>NotificationCenter</strong> ?<br><strong>Answer</strong> : The biggest difference between <strong>KVO</strong> and <strong>NotificationCenter</strong> is that KVOtracks specific changes to an object or property , while <strong>NotificationCenter</strong> is used to track generic events.</p><p><strong>Question : Explain JSONEncoder and JSONDecoder in Swift4 ?<br></strong>Answer : JSONEncoder and JSONDecoder classes which can easily convert an object to encoded JSON representation.</p><p><strong>Question : What is deeplinking in mobile application?</strong><br><strong>Answer</strong> : Using Deep linking user can pass data to the application from any platform like, website or any other application. By tapping on the link, user can pass necessary data to the application and user will redirect to the application.</p><p><strong>Question : What are the table view delegate methods?<br>Answer : </strong><br><strong>Datasources methods<br>@required</strong></p><blockquote>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;</blockquote><blockquote>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;</blockquote><p><strong>@optional</strong></p><blockquote>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;</blockquote><blockquote>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;</blockquote><blockquote>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;</blockquote><blockquote>- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;</blockquote><blockquote>- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;</blockquote><blockquote>- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;</blockquote><p><strong>Delegate methods :</strong> all optional methods</p><p><strong>@optional</strong></p><blockquote>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;</blockquote><blockquote>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;</blockquote><blockquote>- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;</blockquote><blockquote>- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;<br> (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;</blockquote><blockquote>- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;</blockquote><p><strong>Question :What is Guard keyword in swift ?</strong><br><strong>Answer : </strong><br><strong>Guard Keyword :</strong> Guard is basically a safe way to create a constant that is non optional and if it is nil , if it does return nil, we are just going to go ahead and return out of that function so that we don’t have a crash.</p><p><strong>Question : What are benefits of</strong> <strong>Guard ?<br>Answer :</strong> There are two big benefits to guard. One is avoiding the pyramid of doom, as others have mentioned — lots of annoying if let statements nested inside each other moving further and further to the right. The other benefit is provide an early exit out of the function using break or using return</p><p><strong>Question :</strong> What is the question mark ? in Swift?<br><strong>Answer : </strong>The question mark ? is used during the declaration of a property, as it tells the compiler that this property is <em>optional</em>. The property may hold a value or not, in the latter case it’s possible to avoid runtime errors when accessing that property by using ?. This is useful in optional chaining</p><p>var optionalName : String? = “John”</p><p>if optionalName != nil {</p><p>print(“Your name is \(optionalName!)”)</p><p>}</p><h4>Question : What is the use of double question marks ???</h4><p><strong>Answer :<br></strong> To provide a default value for a variable.<br>let missingName : String? = nil<br>let realName : String? = “John Doe”<br>let existentName : String = missingName ?? realName</p><h4>Question : What is the use of exclamation mark !</h4><p><strong>Answer </strong>:<br>Highly related to the previous keywords, the ! is used to tell the compiler that I <em>know definitely</em>, this variable/constant contains a value and please use it (i.e. please unwrap the optional). From question 1, the block that executes the ifcondition is true and calls a forced unwrapping of the optional’s value. There is a method for avoiding forced unwrapping which we will cover below.</p><h4>Question : What is the difference between let and var in Swift?</h4><p><strong>Answer :</strong> The let keyword is used to declare constants while var is used for declaring variables.</p><p>let someConstant = 10<br>var someVariable : String</p><p>Here, we used the : string to explicitly declare that someVariable will hold a string. In practice, it’s rarely necessary — especially if the variable is given an initial value — as Swift will infer the type for you. It is a compile-time error trying to use a variable declared as a constant through let and later modifying that variable.</p><h4>Question : What is the difference between functions and methods in Swift?</h4><p>Functions are globally scoped while methods belong to a certain type.<strong>Question : Difference between function and method in swift ?<br>Answer :</strong> when a function is defined with in the curly braces of a class it is no longer called a function but instead it is called a method.<br><strong>Methods</strong> is always associated with the object of the class.<br><strong>Function</strong> are not associated with the object of the class. To called a function there is no need to create object of any class.</p><p>print (arc4random(3)) is a function not a method</p><p><strong>Question : What is “if let” statement in swift 4 ?<br>Answer :<br>if let userSetDestibnation = Destination</strong> {<br>print(“driving towards “+ userSetDestination)<br>}<br>if let is basically the syntax of optional binding in swift 4 , if we examin the above statement little closer</p><p>using the let keyword we create the new constant and the value will be set to the value of the <strong>destination optional variable</strong> and the line with in the curly braces of the <strong>if let statement</strong> will be execute only if the <strong>destination</strong> <strong>variable</strong> does not nil.<br>Benefit to use the <strong>if let statement</strong> or <strong>Optional binding </strong>is there is no need to force unwrapping and code is safer , will not lead to any bug or crash.</p><p><strong>Question</strong> : <strong>What is the Swift main advantage ?<br>Answer</strong> : To mention some of the main advantages of Swift:</p><ul><li>Optional Types, which make applications crash-resistant</li><li>Built-in error handling</li><li>Closures</li><li>Much faster compared to other languages</li><li>Type-safe language</li><li>Supports pattern matching</li></ul><p><strong>Question</strong> : <strong>What are tuples in swift language?</strong><br><strong>Answer</strong> : Tuples are used to return multiple values from a function call e.g<br> let person = (name : “jain”, age: “10”)<br> person.name — → jain<br> person.age — → 10</p><p><strong>Question</strong> : <strong>What is dynamic dispatch in iOS?</strong><br><strong>Answer</strong> : Dynamic dispatch is the process of selection polymorphic operation (method or function )at run time.<br>Dynamic dispatch is used to decide which polymorphic method will call at run time.</p><p><strong>Question</strong> : <strong>What is KVO and KVC in iOS ?</strong><br><strong>Answer</strong> :<br><strong>KVO</strong> stands for <strong>Key value observer</strong> that allow a <strong>controller or class</strong> to observe the <strong>changes to a property</strong>. In KVO, an object can ask to be notified of any changes to a property , whenever a property changes its value, then the observer is automatically notified.</p><p><strong>KVC </strong>stands for <strong>key value coding</strong> by which an objects property can be accessed using strings at <strong>run time</strong> rather than having to statically know the property at development time.</p><p><strong>Question : What is the purpose of using IBAction and IBOutlets in iOS ?</strong><br><strong>Answer :</strong> IBAction and IBOutlets are macros defined to denote methods and variables in interface builder.<br>IBAction is associated with methods and IBOutlets are associated with variables/properties.<br>IBAction and IBOutlets signify that variables and methods can be used in interface builder to link the UI element.</p><p><strong>Question : What is Grand Central Dispatch (GCD) Objective -C ?<br>Answer : </strong>GCD is a library that provide low level object based API ti run task concurrently while managing the threads</p><p><strong>Types Of GCD : </strong><br><strong>Dispatch_Queue </strong>: Dispatch queue is responsible to execute the task in first in first out order (FIFO).<br><strong>Serial Dispatch Queue</strong> : This queue executes one task at a time in serial order.<br><strong>Concurrent Dispatch Queue</strong> : This Queue executes as many task as it can execute without waiting for the started task to finish.<br><strong>Main Dispatch Queue</strong> : Globally available serial queue that executes task on the applications main thread.</p><p><strong>Question :</strong> <strong>What is size class in ios ?</strong><br><strong>Answer :</strong> Size Class is a new technology iOS 8 onwards to allow user tio customize application UI for a given device based on its orientation and screen size.<br>Before iOS 8 developer had to use multiple checks to handle the UI Elements for the different screen size.</p><p><strong>Question</strong> : <strong>What is the lifecycle of the viewController?</strong><br><strong>Answer</strong> :</p><p><strong>i). LoadView</strong> : It is only called when the view controller is created programmatically. This makes it a good place to create your views in code.<br><strong>ii). ViewDidLoad<br>iii). ViewWillAppear<br>iv). ViewDidAppear<br>v). ViewWillDisappear<br>vi). ViewDidDisappear</strong><br><strong>vii). ViewWillLayoutSubviews</strong> : If you are not using constraints or Auto Layout you probably want to update the subviews here<br><strong>viii). ViewDidLayoutSubviews</strong> : This event notifies the view controller that the subviews have been setup. It is a good place to make any changes to the subviews after they have been set.</p><p><strong>Question : What is the application lifecycle of iOS ?</strong><br><strong>Answer</strong> : <br>1. <strong>didFinishLaunchingWithOptions : </strong>Very first method of the ios application , it is invoked when the application launches.<br><strong>2. applicationWillEnterForeground : </strong>this method will invoked when the application enter in foreground state from the background or killed state.<strong><br>3 . applicationDidBecomeActive : </strong>This method is call after the application enter in foreground to finish up the transition to foreground.<strong><br>4 . applicationWillResignActive : </strong>This method will called when the application is about to inactive e.g when the user receives a phone call and press the home the home button.<strong><br>5 . applicationWillTerminate : </strong>this method invoked when the user killed the application from the memory.</p><p><strong>Question</strong> : <strong>What are the differences in table and collection in iOS ?</strong><br><strong>Answer</strong> : <br>1 . table is consists of single column layout and have top to down scrolling.<br>2. collection is consists of grid layout/multiple column layout and also have vertical and horizontal scrolling.<br>3. Collection view uses customizable layout while table view uses single column layout.</p><p><strong>Question : What is the difference ANY and ANYOBJECT ?<br></strong>Answer : According to Apple’s Swift documentation:</p><ul><li><strong><em>Any</em></strong><em> can represent an instance of any type at all, including function types and optional types.</em></li><li><strong><em>AnyObject </em></strong><em>can represent an instance of any class type.</em></li></ul><p><strong>Question</strong> : <strong>What’s the difference between a xib and a storyboard?Answer : </strong>Both are used in Xcode to layout screens (view controllers). A xib defines a single View or View Controller screen, while a storyboard shows many view controllers and also shows the relationship between them.</p><p><strong>Question</strong> : <strong>What’s the difference optional between nil and .None?<br>Answer</strong> : There is no difference. <strong>Optional.None</strong> (<strong>.None</strong> for short) is the correct way of initializing an optional variable lacking a value, whereas <strong>nil</strong> is just syntactic sugar for <strong>.None</strong>. Check this <a href="https://www.raywenderlich.com/110982/swift-interview-questions-answers">out</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2af44bc7e748" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Push Notification in iOS Mobile Application]]></title>
            <link>https://zenshubham09.medium.com/push-notification-in-ios-mobile-application-d80d52a1b608?source=rss-85c3f69e9ab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d80d52a1b608</guid>
            <category><![CDATA[push-notification]]></category>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[swift-4]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Shubham Jain]]></dc:creator>
            <pubDate>Wed, 14 Mar 2018 04:03:31 GMT</pubDate>
            <atom:updated>2018-03-14T04:03:31.709Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://plus.google.com/103521365322037986439">+ShUBHAm JAin</a></p><h3>Push Notification in iOS Mobile Application</h3><p>For iOS apps, you can implement Firebase Cloud Messaging in two following ways:</p><ul><li>Receive basic push notification messages up to 4KB over the Firebase Cloud Messaging APNs interface.</li><li>Send messages upstream and/or receive downstream data payloads up to 4KB in foregrounded apps.</li></ul><h3>Add Firebase to your iOS project</h3><p>For iOS client apps, you can implement Firebase Cloud Messaging in two complementary ways:</p><ul><li>Receive basic push messages up to 4KB over the Firebase Cloud Messaging APNs interface.</li><li>Send messages upstream and/or receive downstream data payloads up to 4KB in foregrounded apps.</li></ul><p>Add Firebase to your iOS project</p><h3>Prerequisites</h3><p>Before you begin, you need a few things set up in your environment:</p><ul><li>Xcode 8.0 or later</li><li>An Xcode project targeting iOS 8 or above</li><li>Swift projects must use Swift 3.0 or later</li><li>The bundle identifier of your app</li><li>CocoaPods 1.2.0 or later</li><li>For Cloud Messaging:</li><li>A physical iOS device</li><li>An Apple Push Notification Authentication Key for your <a href="https://www.google.com/url?sa=D&amp;q=https%3A%2F%2Fdeveloper.apple.com%2Faccount&amp;authuser=0">Apple Developer account</a></li><li>In Xcode, enable Push Notifications in <strong>App &gt; Capabilities</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*a4AtIiP7qNAH7Fiy.png" /></figure><p><strong>Steps to install Cocoapods on your mac machine:</strong></p><p><strong>Step1 :</strong> if cocoapods is not install on your machine , first install it on machine using the following command on terminal sudo gem install cocoapods</p><p><strong>Step 2 : </strong>Export the to</p><p><strong>export PATH=$PATH:/Library/Ruby/bin</strong></p><p>Step 3: To check the version of cocoapods that you install on your machine</p><p><strong>Pod — version</strong></p><p><strong>Step 4</strong>: Open the terminal to go to your project directory using</p><p>$ cd /Users/xyz/Documents/FireBaseOne/FirebaseDemo</p><p><strong>Step 5</strong>: Initialise the pod</p><p>Pod init</p><p>Open the pod file using the command</p><p>Open Podfile</p><p>And add the following in the podfile</p><p>‘Firebase’, ‘~&gt; 3.0’</p><p>‘Firebase/Messaging’, ‘~&gt; 3.0’</p><p><strong>Step 6</strong> : Install the pod</p><p>Pod install</p><p><strong>Step 7 </strong>: Now open the xcworkspace using the command</p><p>open your-project.xcworkspace</p><p><strong>Step 8</strong> : Now go to firebase console and create a new project</p><p>Fill the application name and country name then add the bundle identifier of the application to the corresponding text field.</p><p>Now Download the config file and add the GoogleService-info.plist file to the xcode project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*znIanzDPLP_GHdNk." /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VYqwhXc77kkMOSCM." /></figure><p>Install the pod that we already install using the command line</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fnnEYu9VGofl0Ajy." /></figure><h3>setUp Firebase in your app</h3><p>You will need to add Firebase initialization code in your app.Import the firebase module in your appdelegate class and configure a shared instance as shown below <strong>AppDelegate.h</strong></p><pre>#import &lt;FirebaseMessaging/FirebaseMessaging.h&gt;<br>#import &lt;UserNotifications/UserNotifications.h&gt;</pre><pre>@interface AppDelegate : UIResponder &lt;UIApplicationDelegate,<br>                                       FIRMessagingDelegate,<br>                                       UNUserNotificationCenterDelegate&gt; <br>{</pre><pre>// conform the firebase delegate as above</pre><pre>}<br>@end</pre><p><strong>AppDelegate.m</strong></p><pre>@import Firebase;<br>@import UserNotifications;<br>@import FirebaseMessaging;<br></pre><pre>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions<br>{</pre><pre> [FIRApp configure];<br>#if defined(__IPHONE_10_0) &amp;&amp; __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= __IPHONE_10_0</pre><pre>    [UNUserNotificationCenter currentNotificationCenter].delegate = self;<br>    [FIRMessaging messaging].delegate = self;</pre><pre>#endif</pre><pre>[self registerRemoteNotification];</pre><pre>[[NSNotificationCenter defaultCenter] <br>  addObserver:self selector:@selector(tokenRefreshCallback:) <br>  name:kFIRInstanceIDTokenRefreshNotification object:nil ];</pre><pre>}<br></pre><pre>- (void)applicationDidEnterBackground:(UIApplication *)application<br>{<br>    [[FIRMessaging messaging] setShouldEstablishDirectChannel:NO];<br>}</pre><pre>- (void)applicationDidBecomeActive:(UIApplication *)application<br>{<br> // jump to the custom connectToFirebase method defination</pre><pre>    [self connetToFireBase];<br>}<br></pre><pre>-(void)registerRemoteNotification<br>{<br>    if (floor(NSFoundationVersionNumber) &lt;= NSFoundationVersionNumber_iOS_9_x_Max) {<br>        UIUserNotificationType allNotificationTypes =(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);<br>        UIUserNotificationSettings *settings =[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];<br>        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];<br>    }<br>    else<br>    {<br>        // iOS 10 or later<br>        [UNUserNotificationCenter currentNotificationCenter].delegate = self;<br>        UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert| UNAuthorizationOptionSound| UNAuthorizationOptionBadge;</pre><pre>        [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {<br>            NSLog(@&quot;Error in push registration  = %@&quot;,error);<br>        }];<br>                [FIRMessaging messaging].delegate = self;<br>    }</pre><pre>    [[UIApplication sharedApplication] registerForRemoteNotifications];<br>}</pre><pre>- (void)application:(UIApplication *)application<br>        didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{</pre><pre>        NSLog(@&quot;device Token = %@&quot;,deviceToken);<br>       [FIRMessaging messaging].APNSToken = deviceToken;<br>}</pre><pre>- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {<br>    if (error.code == 3010) {<br>        NSLog(@&quot;Push notifications are not supported in the iOS Simulator.&quot;);<br>    }<br>    else {<br>        NSLog(@&quot;application:didFailToRegisterForRemoteNotificationsWithError: %@&quot;, error);<br>    }<br>}<br></pre><pre>- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {</pre><pre>    [[UIApplication sharedApplication] registerForRemoteNotifications];</pre><pre>    if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground  )<br>    {<br>        // opened Application from a push notification when the app was on background or inactiva state<br>        [self callCustomMethod];</pre><pre>    }<br>}<br></pre><pre>-(void)application:(UIApplication *)application didReceiveRemoteNotification:<br>       (NSDictionary *)userInfo fetchCompletionHandler:(void (^)<br>       (UIBackgroundFetchResult))completionHandler {<br>        NSLog(@&quot;Push iOS9 =  %@&quot;, userInfo);</pre><pre>       [[FIRMessaging messaging] appDidReceiveMessage:userInfo];<br>       if ( application.applicationState == UIApplicationStateInactive ||<br>            application.applicationState == UIApplicationStateBackground)<br>       {<br>       // opened Application from a push notification when <br>          the app was on background or inactiva state<br>        [self callCustomMetod];<br>       }</pre><pre>    completionHandler(UIBackgroundFetchResultNewData | UIBackgroundFetchResultNoData | UIBackgroundFetchResultFailed);<br>}<br></pre><pre>/* </pre><pre> Push Notification will be shown while app is in foregroung from iOS 10 Onwards</pre><pre> First  Include            #import &lt;UserNotifications/UserNotifications.h&gt;<br> second Include            &lt;UNUserNotificationCenterDelegate&gt;</pre><pre>*/<br>- (void)userNotificationCenter:(UNUserNotificationCenter* )center <br>        willPresentNotification:(UNNotification* )notification <br>        withCompletionHandler:(void (^)<br>        (UNNotificationPresentationOptions options))completionHandler {<br>    NSLog(@&quot;Push iOS10 (Foreground) =  %@&quot;,notification.request.content.userInfo);<br>    completionHandler(UNNotificationPresentationOptionAlert |<br>                      UNNotificationPresentationOptionBadge | <br>                      UNNotificationPresentationOptionSound);</pre><pre>}</pre><pre>/*<br>    Call this method when user want to open app while in <br>    foreground on tapping push notification<br> */<br></pre><pre>- (void)userNotificationCenter:(UNUserNotificationCenter *)center<br>didReceiveNotificationResponse:(UNNotificationResponse *)response<br>         withCompletionHandler:(void (^)())completionHandler<br>{<br>    NSLog(@&quot;Push iOS10 (Background/Closed) = %@&quot;, response.notification.request.content.userInfo);<br>    completionHandler(UNNotificationPresentationOptionAlert |<br>                      UNNotificationPresentationOptionBadge |<br>                      UNNotificationPresentationOptionSound);</pre><pre>}<br>-(void)tokenRefreshCallback:(NSNotification *)notification{<br>    NSString * refreshedToken = [[FIRInstanceID instanceID]token];<br>    NSLog(@&quot;refresh Token is :  %@&quot;,refreshedToken);<br>    [self connetToFireBase];<br>    <br>}</pre><pre>-(void)connetToFireBase<br>{<br>    [[FIRMessaging messaging] setShouldEstablishDirectChannel:YES];<br>     NSLog((@&quot;Connected To Firebase&quot;));<br>}</pre><p>After the above stuff you are done with the coding part on your Xcode.</p><p>Configure APNs with the FCM Firebase cloud messaging APNs interface uses Apple Push Notification Services to send messages upto 4 KB to your application , including when the app is in background state. To enable sending push notification through the APNs , you need</p><ol><li>Push notification authentication key for your apple developer account.Firebase uses this token to sen push notification in application.</li><li>Provisioning profile for that app ID.</li></ol><p><strong>Create Authentication Key:</strong></p><ol><li>go to your developer account then go to <strong>certificates, identifier &amp; profiles</strong> and under keys , select All</li><li>click the add button(+)</li><li>Enter description for the auth key</li><li>under key services , select APNs checkbox and click on continue.</li><li>click confirm and download.Save your key , this is one time download , this key can not be retrieved.</li></ol><p>Create an App ID: App ID is an identifier that uniquely identify an app</p><ol><li>go to apple developer account</li><li>go to <strong>certificates, identifier &amp; profiles</strong></li><li>In drop down menu select iOS Apps and navigate identifiers app IDs</li><li>click the + button to create the new app ID</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*KSNf0YeYfHiaw-70.png" /></figure><p>To Create a new App ID</p><ol><li>input a Name for your app ID</li><li>choose app id prefix</li><li>in App Id Suffix section, select <strong>Explicit App ID , </strong>input your bundle identifier. The Value of bundle identifier shoud match the value that you are using in the apps info.plist and the value you are using to get a configuration for FCM.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*LTfr9OpGReq_rKQN.png" /></figure><ol><li>In App Services section , check the <strong>Push Notification </strong>option</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*rGe8CsRJYcww6Y-C.png" /></figure><ol><li>click continue and check all input are correct.</li><li>click register to create the app id.</li></ol><p><strong>Create Provisioning profile</strong></p><ol><li>go to apple developer account</li><li>go to <strong>Certificates, Identifiers and Profiles</strong></li><li>select ios apps in drop down menu and go to Provisioning profile and select all</li><li>click on <strong>+</strong> icon to create a provisioning profile</li><li>select <strong>iOS App Development </strong>as provisioning type for development purpose, click continue</li><li>in drop down select the <strong>App ID </strong>that you want to use, click continue</li><li>select iOS Development certificate of the app ID, click continue</li><li>select the iOS Devices that you want to include the Provisioning profile , click continue</li><li>provide name for the provisioning profile, click generate</li><li>click <strong>Download </strong>to save the provisioning profile on mac</li><li>Double click the provisioning profile to install it.</li></ol><p>If <em>you liked this article, please following me on Medium. When I have something new and awesome to share. It’s the best way to find out when I write more articles like this.</em></p><p>iOSBlogger : <a href="https://zenshubham.blogspot.com/2018/03/pushnotification.html">https://zenshubham.blogspot.com/2018/03/pushnotification.html</a></p><p><strong>Thanks</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d80d52a1b608" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Native Advanced Ads in iOS mobile Application]]></title>
            <link>https://zenshubham09.medium.com/nativeads-3646a540ef55?source=rss-85c3f69e9ab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3646a540ef55</guid>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[admob]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[native-ads]]></category>
            <dc:creator><![CDATA[Shubham Jain]]></dc:creator>
            <pubDate>Mon, 12 Mar 2018 15:58:36 GMT</pubDate>
            <atom:updated>2018-03-12T15:58:36.565Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://plus.google.com/103521365322037986439">+ShUBHAm JAin</a></p><h3>Native Advanced Ads in iOS Mobile Application</h3><p>Integrating the Google Mobile Ads SDK into an app is the first step towards displaying ads and earning revenue.Once that is done then you can implement the ads in different formats.</p><p>PreRequisites:</p><ol><li>Use Xcode 8.0</li><li>deployment target should be 6.0 or higher</li><li>create admob account and register the app.</li></ol><p>Integrate the mobile Ads SDK in your application</p><p>It is recommended to integrate the google mobile ads SDKs via the cocoa-pods.</p><p>Open the terminal on your mac and go to project directory</p><pre>Step 1 : initialize the pod in project directory<br>             $ pod init<br>Step 2 : open the pod file <br>             $ open podfile<br>Step 3 : Add the framework in the project taget of the podfile<br>             $ pod &#39;Google-Mobile-Ads-SDK&#39;,&#39;~&gt; version&#39;<br>Step 4 : install the repo<br>             $ pod install --repo update</pre><p><strong><em>Note :</em></strong> <em>user can also integrate google mobile ads sdk manually by downloading it.</em></p><p>Select an Ads Format</p><p>AdMobs offers numbers of different ads format, so you can choose one that best fit in your ios application.</p><p>1. Banner AdsFormat :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*BQ5yHXQl8NGdfA_2.png" /></figure><p>Banner ads are rectangular image or text ads that are placed within apps layout.Banner ads stay on screen while you user is interacting the app and can refresh automatically after a certain period of time.</p><p>2. Interstitial AdsFormat:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*hHYKFZl58Q8Uf0Gh.png" /></figure><p>Interstitials ads are full screen ads that cover the whole interface of the application layout until they are closed by the user.</p><p>3. Native AdsFormat :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*EcPJsfKJu9B9JhUC.png" /></figure><p>Native is a component based ads format that allow you to customize the ads like assets , headlines and calls to action that are presented in the app.</p><p>4. Rewarded AdsFormat :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*2nBDvMZo7VpKhjIw.png" /></figure><p>Rewarded ads are full screen video ads that user have the option of watching in full in exchange for in app-reward.</p><p><strong>Lets start to implement the Native Advanced Ads</strong></p><p>Native Advanced ads is a format in which assets are presented to user via UI elements that are native to platform.</p><p>There are two types of native advanced ads</p><ol><li>App install Ads — represented by GADNativeAppInstallAds class</li><li>Content Ads — represented by GADNativeContentAds class</li></ol><p><strong>Initialize the GADLoader</strong></p><p>Native ads are loaded via the GADLoader object which sends message to their delegate according to the GADLoaderDelegate Protocol.</p><p>Following code demonstrate to initialize the ads in app</p><p><strong>Objective C:</strong></p><pre>@implementation ViewController</pre><pre>- (void)viewDidLoad {<br>  [super viewDidLoad];</pre><pre>  GADMultipleAdsAdLoaderOptions *multipleAdsOptions =<br>      [[GADMultipleAdsAdLoaderOptions alloc] init];<br>  multipleAdsOptions.numberOfAds = 5;</pre><pre>  self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:YOUR_AD_UNIT_ID<br>          rootViewController:self<br>                     adTypes:@[kGADAdLoaderAdTypeNativeContent,<br>                               kGADAdLoaderAdTypeNtiveAppInstall]<br>                     options:@[multipleAdsOptions]];<br>  self.adLoader.delegate = self;<br>  [self.adLoader loadRequest:[GADRequest request]];<br>  }<br>}</pre><pre>- (void)adLoader:(GADAdLoader *)adLoader<br>    didReceiveNativeAppInstallAd:(GADNativeAppInstallAd *)nativeAppInstallAd {<br>   // An app install ad has loaded, and can be displayed.<br>}</pre><pre>- (void)adLoader:(GADAdLoader *)adLoader<br>    didReceiveNativeContentAd:(GADNativeContentAd *)nativeContentAd {<br>   // A content ad has loaded, and can be displayed.<br>}</pre><pre>- (void)adLoaderDidFinishLoading:(GADAdLoader *) adLoader {<br>  // The adLoader has finished loading ads, and a new request can be sent.<br>}</pre><pre>@end</pre><p><strong>Swift 4 :</strong></p><pre>class ViewController: UIViewController, GADNativeAppInstallAdLoaderDelegate,<br>    GADNativeContentAdLoaderDelegate {</pre><pre>  var adLoader: GADAdLoader!</pre><pre>  override func viewDidLoad() {<br>    super.viewDidLoad()</pre><pre>    let multipleAdsOptions = GADMultipleAdsAdLoaderOptions()<br>    multipleAdsOptions.numberOfAds = 5</pre><pre>    adLoader = GADAdLoader(adUnitID: YOUR_AD_UNIT_ID, rootViewController: self,<br>        adTypes: [GADAdLoaderAdType.nativeContent,<br>                  GADAdLoaderAdType.nativeAppInstall],<br>        options: [multipleAdsOptions])<br>    adLoader.delegate = self<br>    adLoader.load(GADRequest())<br>  }</pre><pre>  func adLoader(_ adLoader: GADAdLoader,<br>                didReceive nativeAppInstallAd: GADNativeAppInstallAd) {<br>    // An app install ad has loaded, and can be displayed.<br>  }</pre><pre>  func adLoader(_ adLoader: GADAdLoader,<br>                didReceive nativeContentAd: GADNativeContentAd) {<br>      // A content ad has loaded, and can be displayed.<br>  }</pre><pre>  func adLoaderDidFinishLoading(_ adLoader: GADAdLoader) {<br>      // The adLoader has finished loading ads, and a new request can be sent.<br>  }<br>}</pre><p><strong>Note :</strong> <em>Maximum no of ads limit is 5 and by default is 1</em></p><p><strong>Note :</strong> Always test with test ads and the easiest way to load test ads use dedicated test IDs for native advanced ads</p><p>ca-app-pub-3940256099942544/3986624511</p><p><strong>The Ad view Classes :</strong></p><p>for each ads format there is a corresponding “ad view” class GADNativaAppInstallAdView</p><p>for app install view and GADNativeContentAdView for content ads.</p><p>Ad view class also provide <strong>IBOutlet</strong> used to registered the view used for each individual assets, and a method to registered <strong>GADNativeAd</strong> object itself.Register a view allow SDK to automatically handle the following task</p><ol><li>Recording clicks</li><li>Recording impression</li><li>Display AdChoice overlay</li></ol><p><strong>AdChoice Overlay :</strong> adChoice overlay is added to a view by SDK. Leave space in native ad view for automatically inserted adChoice logo.</p><p><strong>Ad Attribution : </strong>display an ad attribution to denote that the view is an advertisement.</p><p>Layout UIView in xib file:</p><p>First step to layout the UIView of displaying the Native Ads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*K7akvKgQTTeRw1ZF.png" /></figure><p>Example for native install ads</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*qdNYrbpEVQCJLWQJ.png" /></figure><p>link the UIElement to the IBOutlets as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*Gzzb34bPVrEooZd4.png" /></figure><p><strong>Display native advanced ads :</strong></p><p><strong>Objective C :</strong></p><pre>#import &quot;ViewController.h&quot;</pre><pre>// Native Advanced ad unit ID for testing.</pre><pre>static NSString *const TestAdUnit = @&quot;ca-app-pub-3940256099942544/3986624511&quot;;</pre><pre>@interface ViewController () &lt;GADNativeAppInstallAdLoaderDelegate, GADNativeContentAdLoaderDelegate&gt;</pre><pre>/// You must keep a strong reference to the GADAdLoader during the ad loading<br>/// process.<br>@property(nonatomic, strong) GADAdLoader *adLoader;</pre><pre>/// The native ad view that is being presented.<br>@property(nonatomic, strong) GADUnifiedNativeAdView *nativeAdView;<br>@end</pre><pre>#pragma mark GADNativeAppInstallAdLoaderDelegate implementation</pre><pre>- (void)adLoader:(GADAdLoader *)adLoader<br>    didReceiveNativeAppInstallAd:(GADNativeAppInstallAd *)nativeAppInstallAd {<br>  // Create and place ad in view hierarchy.<br>  GADNativeAppInstallAdView *appInstallAdView =<br>      [[[NSBundle mainBundle] loadNibNamed:@&quot;NativeAppInstallAdView&quot;<br>                                     owner:nil<br>                                   options:nil] firstObject];<br>  // TODO: Make sure to add the GADNativeAppInstallAdView to the view hierarchy.</pre><pre>  // Associate the app install ad view with the app install ad object. This is required to make the<br>  // ad clickable.<br>  appInstallAdView.nativeAppInstallAd = nativeAppInstallAd;</pre><pre>  // Populate the app install ad view with the app install ad assets.<br>  // Some assets are guaranteed to be present in every app install ad.<br>  ((UILabel *)appInstallAdView.headlineView).text = nativeAppInstallAd.headline;<br>  ((UIImageView *)appInstallAdView.iconView).image = nativeAppInstallAd.icon.image;<br>  ((UILabel *)appInstallAdView.bodyView).text = nativeAppInstallAd.body;<br>  ((UIImageView *)appInstallAdView.imageView).image =<br>      ((GADNativeAdImage *)[nativeAppInstallAd.images firstObject]).image;<br>  [((UIButton *)appInstallAdView.callToActionView)setTitle:nativeAppInstallAd.callToAction<br>                                                  forState:UIControlStateNormal];</pre><pre>  // Other assets are not, however, and should be checked first.<br>  if (nativeAppInstallAd.starRating) {<br>    ((UIImageView *)appInstallAdView.starRatingView).image =<br>        [self imageForStars:nativeAppInstallAd.starRating];<br>    appInstallAdView.starRatingView.hidden = NO;<br>  } else {<br>    appInstallAdView.starRatingView.hidden = YES;<br>  }</pre><pre>  if (nativeAppInstallAd.store) {<br>    ((UILabel *)appInstallAdView.storeView).text = nativeAppInstallAd.store;<br>    appInstallAdView.storeView.hidden = NO;<br>  } else {<br>    appInstallAdView.storeView.hidden = YES;<br>  }</pre><pre>  if (nativeAppInstallAd.price) {<br>    ((UILabel *)appInstallAdView.priceView).text = nativeAppInstallAd.price;<br>    appInstallAdView.priceView.hidden = NO;<br>  } else {<br>    appInstallAdView.priceView.hidden = YES;<br>  }</pre><pre>  // by default userInteractionEnabled set to YES<br>  // for custom use set the property userInteractionEnabled to NO.</pre><pre>  appInstallAdView.callToActionView.userInteractionEnabled = NO;<br>}</pre><p><strong>Swift 4 :</strong></p><pre>// Mark: - GADNativeAppInstallAdLoaderDelegate</pre><pre>func adLoader(_ adLoader: GADAdLoader,<br>    didReceive nativeAppInstallAd: GADNativeAppInstallAd) {<br>  // Create and place the ad in the view hierarchy.<br>  let appInstallAdView = Bundle.main.loadNibNamed(&quot;NativeAppInstallAdView&quot;, owner: nil,<br>      options: nil)?.first as! GADNativeAppInstallAdView<br>  // TODO: Make sure to add the GADNativeAppInstallAdView to the view hierarchy.</pre><pre>  // Associate the app install ad view with the app install ad object. This is required to make<br>  // the ad clickable.<br>  appInstallAdView.nativeAppInstallAd = nativeAppInstallAd</pre><pre>  // Populate the app install ad view with the app install ad assets.<br>  // Some assets are guaranteed to be present in every app install ad.<br>  (appInstallAdView.headlineView as! UILabel).text = nativeAppInstallAd.headline<br>  (appInstallAdView.iconView as! UIImageView).image = nativeAppInstallAd.icon?.image<br>  (appInstallAdView.bodyView as! UILabel).text = nativeAppInstallAd.body<br>  (appInstallAdView.imageView as! UIImageView).image =<br>      (nativeAppInstallAd.images?.first as! GADNativeAdImage).image<br>  (appInstallAdView.callToActionView as! UIButton).setTitle(<br>      nativeAppInstallAd.callToAction, for: UIControlState.normal)</pre><pre>  // Other assets are not, however, and should be checked first.<br>  let starRatingView = appInstallAdView.starRatingView<br>  if let starRating = nativeAppInstallAd.starRating {<br>    (starRatingView as! UIImageView).image = imageOfStarsFromStarRating(starRating)<br>    starRatingView?.isHidden = false<br>  } else {<br>    starRatingView?.isHidden = true<br>  }</pre><pre>  let storeView = appInstallAdView.storeView<br>  if let store = nativeAppInstallAd.store {<br>    (storeView as! UILabel).text = store<br>    storeView?.isHidden = false<br>  } else {<br>    storeView?.isHidden = true<br>  }</pre><pre>  let priceView = appInstallAdView.priceView<br>  if let price = nativeAppInstallAd.price {<br>    (priceView as! UILabel).text = price<br>    priceView?.isHidden = false<br>  } else {<br>    priceView?.isHidden = true<br>  }</pre><pre>  // userInteractionEnabled set to true by default<br>  // for customs user set userInteractionEnabled to false.<br>  (appInstallAdView.callToActionView as! UIButton).isUserInteractionEnabled = false<br>}</pre><p><strong>Handled a Failed native ads request :</strong></p><p><strong>Objective C:</strong></p><pre>- (void)adLoader:(GADAdLoader *)adLoader didFailToReceiveAdWithError:(GADRequestError *)error {<br>    NSLog(@&quot;%@ failed with error: %@&quot;, adLoader, error);<br>}</pre><p><strong>Swift 4 :</strong></p><pre>public func adLoader(_ adLoader: GADAdLoader,<br>    didReceive nativeContentAd: GADNativeContentAd){<br>        print(&quot;%@ failed with error: %@&quot;, adLoader, error)<br>}</pre><p>If <em>you liked this article, please following me on Medium. When I have something new and awesome to share. It’s the best way to find out when I write more articles like this.</em></p><p>iOSBlogger : <a href="https://zenshubham.blogspot.com/2018/03/native-advanced-ads-in-ios-mobile.html">https://zenshubham.blogspot.com/2018/03/native-advanced-ads-in-ios-mobile.html</a></p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3646a540ef55" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Objective-C project Compatibility with Swift And Visa Versa]]></title>
            <link>https://zenshubham09.medium.com/objective-c-project-compatibility-with-swift-and-visa-versa-cc4bfe9cc2e?source=rss-85c3f69e9ab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc4bfe9cc2e</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-playgrounds]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swift-4]]></category>
            <category><![CDATA[objective-c]]></category>
            <dc:creator><![CDATA[Shubham Jain]]></dc:creator>
            <pubDate>Mon, 12 Mar 2018 09:01:59 GMT</pubDate>
            <atom:updated>2018-03-12T09:01:59.703Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://plus.google.com/103521365322037986439"><strong>+ShUBHAm JAin</strong></a></p><h3><strong>Part-1 : How To Use Swift Class in Objective-C</strong></h3><p>Suppose there are two classes objcClass.h , ShowAlertSwift.swift . currently your entire project is written in objective C language, and you want to migrate your project to swift 4.</p><p>To do so Follow the below mention steps in same sequesnce</p><p><strong>Step 1</strong>: First open your Xcode and go to File-&gt; New-&gt; File and create and new swift file in a target . After creating the swift file an alert will be shown like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*tGJuOnaQyCcLGtsb.png" /></figure><p>click on create bridging header. In Bundle there is bridging header for the target.</p><p><strong>Step 2</strong> : For your target set the following properties in your target build setting</p><pre>1. Defines modules - Yes<br>2. Embedded_Content_Contains_Swift - Yes<br>3. Install Objective-C compatibility header - Yes<br>4. Objective C bridging header - $(SRCROOT)/Sources/SwiftBridging.h<br>5. Product Module Name - projectName</pre><h4>Note : Define modules should be YES in your project build Setting its mandatory and optional for target.</h4><p><strong>Step 3 :</strong></p><blockquote><em>Note : To access swift class in objective C code you have to use the @objc keyword along the class statement like that</em></blockquote><pre>@objc public class ShowAlertSwift: NSObject</pre><p>First create an swift class , <strong>ShowAlertSwift.swift</strong></p><pre>import UIKit</pre><pre>    @objc public class ShowAlertSwift: NSObject {</pre><pre>    @objc func printSome() {<br>       print(&quot;Swift class is successfully integrated with objective C Class&quot;)<br>    }<br>    @objc func test () {<br>        print(&quot;Swift Class is integrated in Objective C Class&quot;)<br>    }<br>}</pre><p>In objectiveClass.h, follow these step to access swift class</p><pre>@class ShowAlertSwift</pre><pre>    @interface ViewController : UIViewController</pre><pre>    @end</pre><p>here there is no need to define an interface again as this interface is already exist in “myproject-swift.h” file. Refer question First to understand clearly or see below</p><pre>@interface ShowAlertSwift: NSObject</pre><pre>-(void)test;<br>-(void)printSome;</pre><pre>@end</pre><p><strong>step 4 </strong>— In objectiveClass.m</p><pre>#import &quot;myproject-swift.h&quot;</pre><pre>@interface UIViewController ()<br>{</pre><pre>}</pre><pre>@implementation<br>- (void)viewDidLoad<br>{<br>     ShowAlertSwift *alertObj = [[ShowAlertSwift alloc]init];<br>     [alertObj test];<br>}</pre><p>if you do not want to #import “myproject-swift.h” in each class then import this header file in your project pre compiled header file (.PCH) .</p><p><strong>Part -2: How to use objective C Classes in Swift Class</strong></p><p>Suppose there is a objective-C class named SupportToSwift and user want to access objective-c class methods and attributes in swift class, To achieve this goel user should follow the following steps</p><p><strong>Step 1</strong>: First Create a objective-C Class in your project, suppose user has created a objective c class named SupportToSwift</p><p>SupportToSwift.<strong>h</strong> File</p><pre>#import &lt;Foundation/Foundation.h&gt;<br>@interface SupportToSwift: NSObject</pre><pre>-(void)test;<br>-(void)printSome;</pre><pre>@end</pre><p>SupportToSwift.<strong>m</strong> File</p><pre>#import &quot;SupportToSwift&quot;</pre><pre>@implementation</pre><pre>-(void)viewComponentVC:(NSString*)command withNotification:<br>                       (NSString *)notification withDelegate:(id)del;</pre><pre>-(void)test{<br>   NSLog(&quot;test method is called from the objective C Class&quot;)<br>}<br>-(void)printSome{<br>    NSLog(@&quot;printSome method is called from the objective C Class&quot;);<br>}</pre><pre>@end</pre><p><strong>Step 2 :</strong> In this step import the “SupportToSwift.h” file in the target bridging header file. like so</p><p>myTarget-Bridging-Header.<strong>h</strong></p><pre>target-Bridging-Header.h <br>#import &quot;SupportToSwift.h&quot;<br>#import &quot;XYZ.h&quot;<br>#import &quot;PQR.h&quot;</pre><p><strong>Step 3 :</strong> Now in the swift class user will access the objective c class behavior (methods or function) and attributes (variables) in the following way</p><pre>@objc  public class SwiftLoginViewController: UIViewController  {</pre><pre>    override public func viewDidLoad() {<br>        super.viewDidLoad()</pre><pre>    }<br>    override public func viewWillAppear(_ animated: Bool) {<br>        super.viewWillAppear(true)<br>        let object:SupportToSwift = SupportToSwift()<br>        object.viewComponentVC(&quot;INITIALIZE_LOGIN_VIEW&quot;,withNotification: &quot;INITIALIZE_LOGIN_VIEW&quot;, withDelegate: delegate)<br>     <br>        object.test()<br>        object.printSome()</pre><pre>    }</pre><p><em>If you liked this article, please following me on Medium. When I have something new and awesome to share. It’s the best way to find out when I write more articles like this.</em></p><p><strong>iOS_Blogger :</strong> <a href="https://zenshubham.blogspot.com/2017/10/how-to-migrate-objective-c-project-to.html">https://zenshubham.blogspot.com/2017/10/how-to-migrate-objective-c-project-to.html</a></p><p><strong><em>Thanks</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc4bfe9cc2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS Biometric Local Authentication]]></title>
            <link>https://zenshubham09.medium.com/ios-biometric-local-authentication-5a29aa2a9cf2?source=rss-85c3f69e9ab4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a29aa2a9cf2</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[local-authentication]]></category>
            <category><![CDATA[swift-4]]></category>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Shubham Jain]]></dc:creator>
            <pubDate>Sun, 11 Mar 2018 18:18:42 GMT</pubDate>
            <atom:updated>2018-07-03T15:06:18.711Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://plus.google.com/103521365322037986439">+ShUBHAm JAin</a></p><p><strong>Implement the TouchID Authentication</strong></p><p>The <em>TouchID/FaceID</em> is a feature based on a framework called Local Authentication, which provides facilities for requesting authentication from users with specified security policies.</p><p>Local Authentication handles everything in context of handling the TouchID/FaceID while using in applications. It will prompt for authentication with custom message which will tell user why we need authentication, so users can place his finger on the home button.</p><p><strong>Local Authentication framework</strong></p><p>LocalAuthentication framework is used to implement the TouchID or FaceID authentication in the iOS Mobile Application.Use of touchId authentication is based on Local Authentication Framework.</p><p>To implement touchId feature first we ned to add LocalAuthentication framework in our project.</p><p>In the Project Navigation</p><p>-&gt; select target -&gt; go to build Phase -&gt;click on Link binary with Libraries-&gt;Add Framework</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*XsCNxXue3qfqEnDt.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*kr8HuxHR0tRYZl_r.png" /></figure><p>Add LocalAuthentication Framework in Project Target</p><p>Now we are ready to write code. In the AppDelegate class import the LocalAuthentication.framework</p><p>using the below statement</p><pre>@import LocalAuthentication;</pre><p>Next Step is to ask framework that the touchID can be applied to a specific device by evaluate the policy function and it will accept two parameters one the policy name that we want to evaluate and second the error code.</p><blockquote><em>Identify the following cases while implementing the TouchID in App:</em></blockquote><pre>Case 1 : Device is enabled with Biometric Sensor or not.<br>Case 2 : At Least one Fingerprint is enrolled in device or not to       check Biometric sensor availability.</pre><p><strong>LAPolicy are of two types,</strong></p><ol><li><strong>deviceOwnerAuthenticationWithBiometrics:</strong> It puts restriction to use only biometric authentication to authenticate the device owner.</li></ol><p><strong>2. deviceOwnerAuthentication:</strong> It will allow the application to authenticate the device owner using biometric or the device password.</p><p>Case 1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*F_TjyZXhM3dly2-F.png" /></figure><p>Case 2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*h9_FobeMY6f5oaeS.png" /></figure><p>Biometric authentication dialog behaves similarly as the one used by LAPolicyDeviceOwnerAuthenticationWithBiometrics. However, instead of “Enter Password” button there is “Enter Passcode” button which, when tapped, switches the authentication method and allows users to enter device passcode.</p><p><strong><em>NOTE:</em></strong></p><p>Biometric authentication will get locked after 5 unsuccessful attempts. After that,users have to unlock it by entering passcode. The passcode can be entered either at Lock Screen or even in app by the means of LAPolicyDeviceOwnerAuthentication.The Lock Screen unlock is preferred user experience because we generaly don’t want users to enter their passcode at app’s request.</p><p>In AppDelegate First check device is enabled with biometry sensor and atleast one fingerprint is enrolled in devicewhen the app is launched at very first time</p><p><strong>LAContext</strong> : An LAContext object represents an authentication context and provide a programmatic interface for evaluating authentication policies.</p><pre>LAContext *context = [[LAContext alloc] init];<br>    NSError *authError = nil;</pre><pre>    Test if fingerprint authentication is available on<br>    the device and a fingerprint has been enrolled.</pre><pre>    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&amp;authError]) {<br>        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:HAS_DEVICE_ENROLLED_TOUCH_ID];<br>        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:HAS_DEVICE_BIOMETRY_SENSOR];</pre><pre>        Biometric policy is successfully evaluated<br>        device is enabled with Biometric sensor and<br>        one fingerprint is enrolled in device.<br>    }<br>    else {<br>        Could not evaluate policy;<br>        look at authError and present an appropriate message to user<br>        if(authError){<br>            if (@available(iOS 11.0, *)) {<br>                if(authError.code == LAErrorBiometryNotAvailable){<br>                    Device is not enable with Biometry sensor<br>                    on iOS version 11 onwards<br>                }<br>                else if(authError.code == LAErrorBiometryNotEnrolled){<br>                    Device is enable with Biometry sensor but<br>                    touchID is not enrolled in Device<br>                }<br>            }<br>            else {<br>                Fallback approach on earlier versions</pre><pre>                if (authError.code == LAErrorTouchIDNotAvailable){<br>                    Device is not enable with Biometry sensor<br>                    on iOS version is below 11<br>                }<br>                else if(authError.code == LAErrorTouchIDNotEnrolled){<br>                    Device is enable with Biometry sensor but<br>                    touchID is not enrolled in Device<br>                }<br>            }<br>        }<br>    }<br>}</pre><p><strong><em>NOTE:</em></strong></p><pre>Before iOS 11 it was TouchIDLockout, touchIDNotAvailable, and touchIDNotEnrolled <br>respectively.</pre><p>In the ViewController class</p><p>First check device has biometry sensor or not in ViewDidLoad method .If yes, Show the biometry authentication option in application.</p><pre>- (void)viewDidLoad<br> { <br>  hasBiometrySensor =  [[NSUserDefaults standardUserDefaults] boolForKey:HAS_DEVICE_BIOMETRY_SENSOR];<br>  if(SHOW_FINGERPRINT_LOGIN &amp;&amp; hasBiometrySensor){<br>       [self.biometryView setHidden:NO];<br>     }<br>     else{<br>          [self.biometryView setHidden:YES];<br>        }<br> }</pre><p>After that if device has biometry option and the touch ID is not registered in device then on touchButton tap ask user to enrolled the touchID in the device</p><pre>-(void)setUPTouchIDInDevice{</pre><pre>      UIAlertActionButton *button = [[UIAlertActionButton alloc] initWithTitle:@&quot;OK&quot;<br>         style:UIAlertActionStyleDefault<br>         andActionHandler:^{<br>         NSURL *url = [NSURL URLWithString:@&quot;App-Prefs:root=TOUCHID_PASSCODE&quot;];<br>         if([[UIApplication sharedApplication] canOpenURL:url]){<br>           [[UIApplication sharedApplication] openURL:url];<br>            NSLog(@&quot;go to device settings to enroll fingerprint&quot;);<br>             }<br>            }];<br>       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@&quot;Touch ID Setup&quot;<br>                    message:@&quot;Please setup Touch ID in your device&quot;<br>                    actionButtons:@[button]<br>                    presentViewController:self<br>                    animation:YES<br>                    andCompletionHandler:nil];<br>      [alert showOPActionAlert];<br>   }</pre><p>After enrolled the touchID in device ask user to enrolled touchID in the Application</p><pre>-(void)enrolledTouchIDInAppliction{<br><br>    LAContext *context = [[LAContext alloc] init];<br>    NSError *authError = nil;<br><br>    Test if fingerprint authentication is available <br>    on the device and a fingerprint has been enrolled.<br><br>    NSString *myLocalizedReasonString = @&quot;Please authenticate using your fingerprint.&quot;;<br><br>    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&amp;authError]) {<br><br>       [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics<br><br>        localizedReason:myLocalizedReasonString<br><br>           reply:^(BOOL success, NSError *error) {<br>           if (success) {<br>              NSLog(@&quot;User authenticated successfully, take appropriate action&quot;);<br>             }<br>             else {<br>                NSLog(@&quot;User did not authenticate successfully, look at error and take appropriate action&quot;);<br>                  if(error.code == -1){<br>                       NSLog(@&quot;Application retry limit exceeded&quot;);<br>                      }<br>                     else if(error.code == LAErrorUserCancel){<br>                       NSLog(@&quot;user has tapped the home button and authentication is canced by user&quot;);<br>                      }<br>                      if (@available(iOS 11.0, *)) {<br>                        if(error.code == LAErrorBiometryLockout){<br><br>                          NSLog(@&quot;Authentication was not successful,<br>                          because there were too many failed biometry attempts(5 consequitive attempts)and biometry is now locked.Passcode is required to unlock biometry&quot;);<br>                         }<br>                        else if(error.code == LAErrorSystemCancel){<br>                          NSLog(@&quot;Authentication was canceled by system (e.g. another application went to foreground).&quot;);<br>                        }<br>                        else if(error.code == LAErrorSystemCancel){<br>                          NSLog(@&quot;Authentication was canceled by system (e.g. another application went to foreground).&quot;);<br>                        }<br>                         else {}<br>                         }<br>                      else {<br>                          // Fallback approach on earlier versions<br>                          if (error.code == LAErrorTouchIDLockout){<br><br>                             NSLog(@&quot;Authentication was not successful,because there were too many failed biometry attempts and biometry is now locked.Passcode is required to unlock biometry&quot;);<br>}<br>else {}<br>       }<br>      }<br>     }];<br>    }<br>    else {<br><br>        if (authError.code) {<br><br>          NSLog(@&quot;There is no need to handle evaluate policy auth    error as user is already handled the policy evaluated error in app delegate if user is not handling the policy evaluated error in app delegate then handle the auth error here.&quot;);<br>        }<br>    }<br>}</pre><p>Once user enrolled the touch ID in application then user is able to perform task by using the fingerprint e.g login in app.</p><p>I have tried to create the high-level workflow for Biometric authentification, this also might help you guys to understand the workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*SXK4c5sVOwufWX6GXKFXUg.jpeg" /></figure><p>Thanks</p><blockquote><strong>If you liked this article, please follioowing me on Medium. When I have something new and awesome to share. It’s the best way to find out when I write more articles like this.</strong></blockquote><p>iOSBlogger : <a href="https://zenshubham.blogspot.com/2018/03/biometric-integration-in-ios-mobile.html">https://zenshubham.blogspot.com/2018/03/biometric-integration-in-ios-mobile.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a29aa2a9cf2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>