<?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 Narendra Jagne on Medium]]></title>
        <description><![CDATA[Stories by Narendra Jagne on Medium]]></description>
        <link>https://medium.com/@nkjagne1?source=rss-f99c68fcaf59------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*xVS1r0dq8s-GDBOddL1BRA.jpeg</url>
            <title>Stories by Narendra Jagne on Medium</title>
            <link>https://medium.com/@nkjagne1?source=rss-f99c68fcaf59------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:34:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nkjagne1/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[Document Picker in Swift 4]]></title>
            <link>https://medium.com/@nkjagne1/document-picker-in-swift-4-db0bebe1347c?source=rss-f99c68fcaf59------2</link>
            <guid isPermaLink="false">https://medium.com/p/db0bebe1347c</guid>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Narendra Jagne]]></dc:creator>
            <pubDate>Sun, 15 Sep 2019 18:30:19 GMT</pubDate>
            <atom:updated>2019-09-15T18:30:19.196Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*NowLO86xa9MMXzBp55y35A.png" /></figure><p>Hello Everyone, I am Narendra Jagne. I am a iOS Developer. Today, I am talking about , how to pick document from your document folder. Onward ios 8 apple introduce UIDocumentPickerViewController to pick document . after that it is very easy for developer to implement it .</p><p>Let’s see the step one by one , following steps are required</p><ul><li>Xcode software</li><li>Paid Membership in Apple Developer Program</li><li>Permission to enable CloudKit in your developer account</li><li>Provisioning Profile</li></ul><p>First , you will create a xcode project and saved it locally . enable the cloud and kaychain Sharing from capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*aAZX_Z7PyFdj79A_2VRybg.png" /></figure><p>After done this , we will do the next things</p><p>Apple provides a <strong>UIDocumentViewController</strong> and <strong>UIDocumentMenuViewController</strong> to access document based apps. But unfortunately <em>iOS 11 deprecated UIDocumentMenuViewController</em>. So we can use UIDocumentViewController.</p><p><strong>MobileCoreServices</strong></p><p>Use uniform type identifier (UTI) information to create and manipulate data that can be exchanged between your app and other apps and services.</p><blockquote><em>import MobileCoreServices</em></blockquote><p>If you import core services then only you can able to do Document types. Document types are what ever you want is that in mobile core services.</p><blockquote><em>let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypeText),String(kUTTypeContent),String(kUTTypeItem),String(kUTTypeData)], in: .import)</em></blockquote><blockquote><em>//Call Delegate</em></blockquote><blockquote><em>documentPicker.delegate = self</em></blockquote><blockquote><em>self.present(documentPicker, animated: true)</em></blockquote><p>And finally confirms UIDocumentPickerDelegate in your class. Implement below delegate methods. The method is called once a document is selected.</p><blockquote><em>func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {</em></blockquote><blockquote><em>print(urls)</em></blockquote><blockquote>}</blockquote><p>Here is the example github link “<a href="https://github.com/narendrajagne/DocumentPickerDemo">https://github.com/narendrajagne/DocumentPickerDemo</a>”</p><p>Happy Coding</p><p>iCoder on implementation : -)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db0bebe1347c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add Event to iCalender Using Swift 4]]></title>
            <link>https://medium.com/@nkjagne1/add-event-to-icalender-using-swift-4-b43ad5f01f71?source=rss-f99c68fcaf59------2</link>
            <guid isPermaLink="false">https://medium.com/p/b43ad5f01f71</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode-10]]></category>
            <category><![CDATA[icalendar]]></category>
            <dc:creator><![CDATA[Narendra Jagne]]></dc:creator>
            <pubDate>Mon, 02 Sep 2019 17:20:04 GMT</pubDate>
            <atom:updated>2019-09-02T17:20:04.476Z</atom:updated>
            <content:encoded><![CDATA[<p>What excited everybody , This is <strong>Narendra Jagne</strong>.<strong> </strong>I am<strong> iOS Application Developer</strong>. Today, we are talking about <strong>How to add event to iCalender ?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RZzoCUtjXQp-mGgHcPN3WA.jpeg" /></figure><p>Using the EventKit framework it is possible to access calendars on an iOS Device. In this tutorial an iCloud Calendar will be created an event will be added to this calendar. This tutorial is made with Xcode 10.1 and built for iOS 12.1.</p><p>Open Xcode and create a new Single View App.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NaU4LuhkyymP5CSD0J_jYA.png" /></figure><p>For product name, use <strong>iOSAddEventExample</strong> and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and choose Next</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xoBLAsEIGXzVr5E2Jleigw.png" /></figure><p>An event will be saved in this calendar so the user needs to grant access to the Calendar. Go to the <strong>Info.plist </strong>and add the following entry</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fXpZtd6YcmE7d6LdLxL_tQ.png" /></figure><p>Go to the <strong>ViewController.swift</strong> file and import the EventKit framework</p><pre>import EventKit</pre><p>Change the <strong>viewDidLoad</strong> method to</p><pre>override func viewDidLoad() {<br>    super.viewDidLoad()<br>        <br>    // 1<br>    let eventStore = EKEventStore()<br>        <br>    // 2<br>    switch EKEventStore.authorizationStatus(for: .event) {<br>    case .authorized:<br>        insertEvent(store: eventStore)<br>        case .denied:<br>            print(&quot;Access denied&quot;)<br>        case .notDetermined:<br>        // 3<br>            eventStore.requestAccess(to: .event, completion:<br>              {[weak self] (granted: Bool, error: Error?) -&gt; Void in<br>                  if granted {<br>                    self!.insertEvent(store: eventStore)<br>                  } else {<br>                        print(&quot;Access denied&quot;)<br>                  }<br>            })<br>            default:<br>                print(&quot;Case default&quot;)<br>    }<br>}</pre><ol><li>An EKEventStore object is created. This represents the Calendar’s database</li><li>The <strong>authorizationStatus(for:) </strong>method returns the authorisation status</li><li>If the status is not yet determined the user is prompted to deny or grant access using the <strong>requestAccess(to:completion:)</strong> method.</li></ol><p>If the access is granted by the user the <strong>insertEvent(store:) </strong>method is called.</p><pre>func insertEvent(store: EKEventStore) {</pre><pre><strong>      let</strong> event:EKEvent = EKEvent(eventStore: store)<br>      <strong>let</strong> startDate = Date()<br>      <em>// 2 hours<br>      </em><strong>let</strong> endDate = startDate.addingTimeInterval(2 * 60 * 60)<br>      event.title = &quot;Test Title&quot;<br>      event.startDate = startDate<br>      event.endDate = endDate<br>      event.notes = &quot;This is a note&quot;<br>      event.calendar = store.defaultCalendarForNewEvents</pre><pre><strong>      do</strong> {</pre><pre><strong>          try</strong> store.save(event, span: .thisEvent)</pre><pre>      } <strong>catch</strong> <strong>let</strong> error <strong>as</strong> NSError {</pre><pre>      print(&quot;failed to save event with error : \(error)&quot;)<br>      }<br>      print(&quot;Saved Event&quot;)<br>}</pre><ol><li>The event has a start date of the current time and an end date of 2 hours from the current time. (2 hours x 60 minutes x 60 seconds)</li><li>An event is created with a title of “Test Title”</li><li>The event is saved into the current calendar.</li></ol><p>This tutorial can only run on an iOS Device, since the iOS Simulator ha no calendars. <strong>Build and Run</strong> the Project. The application needs to be authorised to access the calendar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QqBMepjPslYwCLnTH6C4lw.png" /></figure><p>Next, open the Calendar app on an iOS Device or in Mac OS X. The New Meeting is added to the calendar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3WhNt3whuNWIIZs_M2kQwQ.png" /></figure><p>You can download the source code of the <strong>iOSAddEventExample</strong> at the ioscreator repository on Github “ <a href="https://github.com/narendrajagne/addEventToCalender">https://github.com/narendrajagne/addEventToCalender</a>”</p><p>iCoder on Implementation :-)</p><p>Happy Coding….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b43ad5f01f71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Realm Database Migration in Swift]]></title>
            <link>https://medium.com/@nkjagne1/realm-database-migration-in-swift-30f8de439614?source=rss-f99c68fcaf59------2</link>
            <guid isPermaLink="false">https://medium.com/p/30f8de439614</guid>
            <category><![CDATA[realm]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Narendra Jagne]]></dc:creator>
            <pubDate>Sat, 24 Aug 2019 12:08:52 GMT</pubDate>
            <atom:updated>2019-08-24T12:08:52.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GbCLGfNCoX2xtmXH_Pt0yA.png" /></figure><p>Hello Friend’s , I am <strong>Narendra Jagne</strong>. Today , we are talking about “Realm database migration in swift language for iOS application developments”. Local database is one of the major task in mobile developement. To stored the data locally <strong>Apple</strong> provided the <strong>Coredata</strong> and <strong>Sqlite DB framework . </strong>While importing this two framework you will stored data into your iOS device But ways of this two framework are totally different. Coredata is Object Relational Model , It stored data in the form of objects while in sqlite databse you need to make queries and insert into table. All things are okey while creating table, insert , update and delete but in case of database migration it’s going very complex.</p><p>To make developer life easier and speed on work , Realm local database storage is here. I will tell why we use “Realm Databse ”.</p><ol><li>Realm Database totally free for developer.</li><li>Realm Database easy to integrate and easy to use.</li><li>Less code and more functionality will done.</li><li>You can access all method and class using objects.</li><li>Quick access from database.</li><li>Real time table will be re-load like pagination.</li><li>Realm Database is very lightweighted.</li><li>And one of the major part will be done very easily i.e. <strong>Database Migration.</strong></li></ol><p>Now, It is very easy to upload your new version to <strong>App Store </strong>without affecting old version when we used Realm database migration. Just two days before I had done realm database migration into my current project and using realm framework, <strong>I Achieved</strong> it within the deadline. So, guys In this blog I will discuss following topics.</p><ol><li>How to integrate Realm Database.</li><li>How to use Realm into your projects.</li><li>How to done Realm Database migration.</li></ol><p>Let’s see in deep all topics one by one.</p><h3><strong>How to integrate Realm Database</strong></h3><p>You can integrate realm database two ways into your projects.</p><p>A) By drag and drop framework into your projects.</p><p>B) By installed pod file of realm framework.</p><p>let’s see first <strong>“</strong> <strong>By drag and drop framework into your projects”.</strong></p><p>You can downalod realm database form here “<a href="https://github.com/realm/realm-cocoa">https://github.com/realm/realm-cocoa</a>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDgP9DiFEFbkQRa3BmcHKQ.png" /></figure><p>download zip file of realm master and store it locally in your desktop then unzip it and drag realm folder into your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q0A_CkOCPXlDTeABudSeFQ.png" /></figure><p>Now , we will see other way of integration realm into your projects using cocoapod file.</p><p>Prerequisites :</p><ul><li>Building Realm requires Xcode 8.x.</li><li>If cloning from git, submodules are required: git submodule update --init --recursive.</li></ul><p>Drag and drop ur project directory into terminals</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*kplpe8wpvZ8Ki_7cy6G-0w.png" /><figcaption>(drag your project local directory)</figcaption></figure><p>Now follow the step’s below :</p><ol><li>run command pod init</li><li>open podfile and insert realm framework and save it.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*9Puk7jJrOPPu9762Ah5wfw.png" /><figcaption>(podfile view)</figcaption></figure><p>3. command pod install</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*YKMmi_lv8KgaM7iSANJl8Q.png" /><figcaption>(Installing on runnig ..)</figcaption></figure><p>after installation done open your <strong>“RealmDatabseMigration.xcworkspace” </strong>file.</p><p>Finally integration process is done. Now we will do second step</p><h3>How to use Realm into your projects :</h3><h4>Concepts and Classes Overview</h4><p>To better understand what Realm does, here are some concepts and information about the classes you’ll use in this tutorial:</p><ul><li><strong>Realm</strong>: Realm instances are the heart of the framework. It’s your access point to the underlying database like a Core Data managed object context. You create instances using the Realm() initializer.</li><li><strong>Object</strong>: This is your Realm model. The act of creating a model defines the schema of the database. To create a model, you subclass Object and define the fields you want to persist as properties.</li><li><strong>Relationships</strong>: You create one-to-many relationships between objects by declaring a property of the type of the Object to which you want to refer. You can create many-to-one and many-to-many relationships via a property of type List.</li><li><strong>Write Transactions</strong>: Any operations in the database, like creating, editing or deleting objects, must be performed within <strong>writes</strong> by calling write(_:) on Realminstances.</li><li><strong>Queries</strong>: To retrieve objects from the database you use queries. The simplest form of a query is calling objects() on a Realm instance and passing in the class of the Object you’re looking for. If your data retrieval needs are more complex, you can make use of predicates, chain your queries and order your results.</li><li><strong>Results</strong>: Results is an auto-updating container type that you get back from object queries. They have many similarities with regular Arrays including the subscript syntax.</li></ul><p>With a brief introduction to Realm, it’s time to get your feet wet and build the rest of the project.</p><h4>Your First Model</h4><pre><strong>import</strong> Foundation<br><strong>import</strong> RealmSwift</pre><pre><strong>final</strong> <strong>class</strong> NKJagne: Object {</pre><pre><strong>     dynamic</strong> <strong>var</strong> pickUpArea = &quot;&quot;<br>     <strong>dynamic</strong> <strong>var</strong> dropingArea= &quot;&quot;<br>     <strong>dynamic</strong> <strong>var</strong> cab_No = 0<br>}</pre><p>Now, add data to locally using realm database</p><pre><strong>import</strong> UIKit<br><strong>import</strong> Realm<br><strong>import</strong> RealmSwift</pre><pre><em>// All changes to an object (addition, modification and deletion) must be done within a write transaction.</em></pre><pre><strong>final</strong> <strong>class</strong> NKJagneLocalStorage {</pre><pre><em>// MARK: - Properties<br></em><strong>static</strong> <strong>let</strong> currentSchemaVersion: UInt64 = 3</pre><pre><em>// MARK: - Static Methods<br></em><strong>static</strong> <strong>func</strong> tripStore() <strong>throws</strong> {</pre><pre><strong>     let</strong> fristTrip = NKJagne()<br>     fristTrip.pickUpArea = &quot;Thane&quot;<br>     fristTrip.dropingArea = &quot;Belapur, Navi Mumbai&quot;<br>     fristTrip.cab_No = 9089</pre><pre><strong>     let</strong> secondTrip = NKJagne()<br>     secondTrip.pickUpArea = &quot;Dadar&quot;<br>     secondTrip.dropingArea = &quot;Goregaon&quot;<br>     secondTrip.cab_No = 7845</pre><pre><strong>     let</strong> thirdTrip = NKJagne()<br>     thirdTrip.pickUpArea = &quot;Bandra&quot;<br>     thirdTrip.dropingArea = &quot;Churchget&quot;<br>     thirdTrip.cab_No = 6756</pre><pre><strong>     let</strong> fourthTrip = NKJagne()<br>     fourthTrip.pickUpArea = &quot;Chembur&quot;<br>     fourthTrip.dropingArea = &quot;Andheri&quot;<br>     fourthTrip.cab_No = 3450</pre><pre><strong>     let</strong> realm = <strong>try</strong> Realm()<br>     <strong>try</strong> realm.write {<br>          realm.add([fristTrip, secondTrip, thirdTrip, fourthTrip]<br>      }<br>    }<br>}</pre><p>Finally call tripStore() method to viewdidload of viewcontroller class.like NKJagneLocalStorage.tripStore()</p><p>In this way , you are able store data locally using realm framework.Now we will jump to database migration. how realm database migration done i will describe below.</p><h3>How to done Realm Database migration ?</h3><p>Migration is very simple using realm database . First you need to declared new property which you want add to exit database. see below syntax</p><pre><strong>import</strong> UIKit<br><strong>import</strong> Foundation<br><strong>import</strong> RealmSwift</pre><pre><strong>final</strong> <strong>class</strong> NKJagne: Object {</pre><pre><em>/* old version database properties */<br>     </em><strong>dynamic</strong> <strong>var</strong> pickUpArea = &quot;&quot;<br>     <strong>dynamic</strong> <strong>var</strong> dropingArea = &quot;&quot;<br>     <strong>dynamic</strong> <strong>var</strong> cab_No = 0</pre><pre><em>/* in new version , you need to add one new properties */<br>     </em><strong>dynamic</strong> <strong>var</strong> tripType = &quot;&quot;<br>}</pre><p>Now , you added new property successfully and you need to add migration method to NKJagneLocalStorage medule</p><pre><strong>import</strong> UIKit<br><strong>import</strong> Realm<br><strong>import</strong> RealmSwift</pre><pre><em>// All changes to an object (addition, modification and deletion) must be done within a write transaction.<br></em><strong>final</strong> <strong>class</strong> NKJagneLocalStorage {</pre><pre><em>// MARK: - Properties<br></em><strong>static</strong> <strong>let</strong> currentSchemaVersion: UInt64 = 3</pre><pre><em>// MARK: - Static Methods<br></em><strong>static</strong> <strong>func</strong> tripStore() <strong>throws</strong> {<br>   <br>   <strong>let</strong> fristTrip = NKJagne()<br>   fristTrip.pickUpArea = &quot;Thane&quot;<br>   fristTrip.dropingArea = &quot;Belapur, Navi Mumbai&quot;<br>   fristTrip.cab_No = 9089</pre><pre><strong>   let</strong> secondTrip = NKJagne()<br>   secondTrip.pickUpArea = &quot;Dadar&quot;<br>   secondTrip.dropingArea = &quot;Goregaon&quot;<br>   secondTrip.cab_No = 7845</pre><pre><strong>   let</strong> thirdTrip = NKJagne()<br>   thirdTrip.pickUpArea = &quot;Bandra&quot;<br>   thirdTrip.dropingArea = &quot;Churchget&quot;<br>   thirdTrip.cab_No = 6756</pre><pre><strong>   let</strong> fourthTrip = NKJagne()<br>   fourthTrip.pickUpArea = &quot;Chembur&quot;<br>   fourthTrip.dropingArea = &quot;Andheri&quot;<br>   fourthTrip.cab_No = 3450</pre><pre><strong>   let</strong> realm = <strong>try</strong> Realm()<br>   <strong>try</strong> realm.write {<br>       realm.add([fristTrip, secondTrip, thirdTrip, fourthTrip]<br>     }<br>  }</pre><pre><strong>static</strong> <strong>func</strong> configureMigration() {</pre><pre><strong>    let</strong> config = Realm.Configuration(schemaVersion:             currentSchemaVersion, migrationBlock: { (migration, oldSchemaVersion) <strong>in</strong></pre><pre><strong>        if</strong> oldSchemaVersion &lt; 1 {<br>            migrateFrom0To1(with: migration)<br>        }<br>     })<br>    Realm.Configuration.defaultConfiguration = config<br>}</pre><pre><em>// MARK: - Migrations<br></em><strong>static</strong> <strong>func</strong> migrateFrom0To1(with migration: Migration) {<br><em>// Add an tripType property<br>           </em>migration.enumerateObjects(ofType: NKJagne.className()) {  (<strong>_</strong>, newNKJagne) <strong>in</strong></pre><pre>                   newNKJagne?[&quot;tripType&quot;] = &quot;&quot;<br>                }<br>             }<br>      }</pre><p>Migration method implemented and now we need to call this migration method to appdelegate class.</p><pre><strong>import</strong> UIKit<br><strong>@UIApplicationMain</strong></pre><pre><strong>class</strong> AppDelegate: UIResponder, UIApplicationDelegate {</pre><pre><strong>var</strong> window: UIWindow?</pre><pre><strong>func</strong> application(<strong>_</strong> application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: <strong>Any</strong>]?) -&gt; Bool {</pre><pre><em>       // Override point for customization after application launch.</em></pre><pre><em>      // realm migration configure</em></pre><pre>      NKJagneLocalStorage.configureMigration()</pre><pre><strong>      return</strong> <strong>true</strong></pre><pre>     }<br>}</pre><p>Uhhhhhreeee…Finally we acheived database migration using realm framework . see now how easy it is . it make developer life more easy :-)</p><p>Thanks to Realm team to save lots more time.</p><h3>Conclusion</h3><p>My litle advice to all iOS developer once you try realm you will really findout. It is very easy to use in our ios application. Realm is very lightweight framework and easy to integrated.</p><p>for ready realm database migration code please download the example from my public github repository. “<a href="https://github.com/narendrajagne/RealmMigration">https://github.com/narendrajagne/RealmMigration</a>”</p><p>you can also visit my linkedin profile “<a href="https://www.linkedin.com/in/narendra-jagne-6b32aab4/">https://www.linkedin.com/in/narendra-jagne-6b32aab4/</a>”</p><p>If you like this blog please give some claps and fellow me and give me your feedback it will really helpfull for me.</p><p>iCoder on implementation :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30f8de439614" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Firebase cloud messaging in iOS applications using swift]]></title>
            <link>https://medium.com/@nkjagne1/use-firebase-cloud-messaging-in-ios-applications-using-swift-5e5eb16e56e0?source=rss-f99c68fcaf59------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e5eb16e56e0</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[xcode-10]]></category>
            <category><![CDATA[swift-4]]></category>
            <dc:creator><![CDATA[Narendra Jagne]]></dc:creator>
            <pubDate>Thu, 15 Aug 2019 15:24:03 GMT</pubDate>
            <atom:updated>2019-08-15T15:24:03.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Mk7mwwIHqjxs3JsFWrw0g.jpeg" /></figure><p>Hello friends, I am Narendra Jagne. This is my own expriences which I shared with you for firebase cloud messaging , I used firebase cloud messaging in my chat applications for real time chat . Firebase cloud messaging framework is one of the best framework for real time chat. easy to integrate and easy to implement. In this blog, I will tell you.</p><ul><li>How firebase cloud messaging work .</li><li>How to integrate firebase cloud messaging using pod file.</li><li>How to use firebase cloud messaging framework.</li></ul><p>Let’s see all this thing one by one on deep and see what challenge you will face while using firebase cloud messaging integration .</p><h3><strong>How firebase cloud messaging work :</strong></h3><p>Firebase cloud messaging not only send messaging to android but it also interact with iOS device using APNS (Apple Push Notifications Service ). Interesting right , we are here know that how it worked actually in iOS device and how it interact with iOS Device.</p><p>Their is two things required for FCM one is APNS Certificates which is also known as APNS Auth key and other is the iOS Device which get unique device token (Instant token/Unique identifier ) through APNS. This device token typically requested by device from APNS. those Firebase cloud messaging play here the role of server using this two APNS cers and device token. Note :- Device token is unique for every device .</p><p>Firstly, While using firebase cloud messaging you need to upload this APNS cers in the form of .p12 to firebase console and this allows to talk with APNS Service. So, when your application live on Apple Store then your device requested device token from APNS and this device token send to firebase cloud messaging server and finally firebase send it’s own FCM token on exchange. So, This is a way firebase communated with your device and this way firebase cloud messaging worked.</p><h3><strong>How to integrate firebase cloud messaging using pod file :</strong></h3><p><em>Prerequisites</em></p><ul><li>Install Xcode 10.1 or later.</li><li>Install CocoaPods 1.4.0 or later.</li><li>Open your project in Xcode.</li><li>Your project must target iOS 8 or later.</li><li>Swift projects must use Swift 4.0 or later.</li><li>Set up a physical iOS device or the iOS simulator for running your app.</li></ul><p><em>For Cloud Messaging, you’ll need:</em></p><ul><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">Apple Developer account</a></li><li>In Xcode, enable Push Notifications in <strong>App</strong> &gt; <strong>Capabilities</strong>.</li><li>For all other Firebase products, you can use either a physical iOS device or the iOS simulator.</li><li><a href="https://console.firebase.google.com/">Sign into Firebase</a> using your Google account.</li></ul><h4>Create a Firebase project</h4><p>Before you can add Firebase to your iOS app, you need to create a Firebase project to connect to your iOS app. Register your app with Firebase.After you have a Firebase project, you can add your iOS app to it.</p><ol><li>In the center of the <a href="https://console.firebase.google.com/">Firebase console’s project overview page</a>, click the <strong>iOS</strong> icon to launch the setup workflow.</li><li>If you’ve already added an app to your Firebase project, click <strong>Add app</strong> to display the platform options.</li><li>Enter your app’s <a href="https://cocoacasts.com/what-are-app-ids-and-bundle-identifiers/">bundle ID</a> in the <strong>iOS bundle ID</strong> field.</li><li><em>(Optional)</em> Enter other app information as prompted by the setup workflow.</li></ol><p>5.<strong> App nickname</strong>: An internal, convenience identifier that is only visible to you in the Firebase console</p><p>6. Click <strong>Register app</strong></p><h4>Add a Firebase configuration file</h4><ol><li>Click <strong>Download GoogleService-Info.plist</strong> to obtain your Firebase iOS config file (GoogleService-Info.plist).</li><li>Move your config file into the root of your Xcode project. If prompted, select to add the config file to all targets.</li></ol><h4>Add Firebase SDKs to your app using cocoapod</h4><ol><li>Create a Podfile if you don’t already have one:</li></ol><pre>cd your-project-directory</pre><pre>pod init</pre><pre># Add the pod for Firebase Cloud Messaging<br>pod &#39;Firebase/Messaging&#39;</pre><pre>pod install</pre><pre>open your-project.xcworkspace</pre><h4>Upload your APNs authentication key</h4><p>Upload your APNs authentication key to Firebase. If you don’t already have an APNs authentication key, see <a href="https://firebase.google.com/docs/cloud-messaging/ios/certs">Configuring APNs with FCM</a>.</p><ol><li>Inside your project in the Firebase console, select the gear icon, select <strong>Project Settings</strong>, and then select the <strong>Cloud Messaging</strong> tab.</li><li>In <strong>APNs authentication key</strong> under <strong>iOS app configuration</strong>, click the <strong>Upload</strong> button.</li><li>Browse to the location where you saved your key, select it, and click <strong>Open</strong>. Add the key ID for the key (available in <strong>Certificates, Identifiers &amp; Profiles</strong> in the <a href="https://developer.apple.com/membercenter/index.action">Apple Developer Member Center</a>) and click <strong>Upload</strong>.</li></ol><h3>How to use firebase cloud messaging framework :</h3><h4>Initialize Firebase in your app</h4><p>You’ll need to add Firebase initialization code to your application. Import the Firebase module and configure a shared instance as shown:</p><ol><li>Import the Firebase module in your UIApplicationDelegate:</li></ol><pre>import Firebase</pre><p>2. Configure a <a href="https://firebase.google.com/docs/reference/ios/firebasecore/api/reference/Classes/FIRApp">FirebaseApp</a> shared instance, typically in your app&#39;s application:didFinishLaunchingWithOptions: method:</p><pre>// Use Firebase library to configure APIs<br>FirebaseApp.configure()</pre><h4>Register for remote notifications</h4><p>Either at startup, or at the desired point in your application flow, register your app for remote notifications. Call registerForRemoteNotifications as shown :</p><pre>if #available(iOS 10.0, *) {<br>  // For iOS 10 display notification (sent via APNS)<br>  UNUserNotificationCenter.current().delegate = self<br><br>  let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]<br>  UNUserNotificationCenter.current().requestAuthorization(<br>    options: authOptions,<br>    completionHandler: {_, _ in })<br>} else {<br>  let settings: UIUserNotificationSettings =<br>  UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)<br>  application.registerUserNotificationSettings(settings)<br>}<br><br>application.registerForRemoteNotifications()</pre><pre><a href="https://github.com/firebase/quickstart-ios/blob/653dc7b60030c5037f6323af0e8ee659c086c622/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55">AppDelegate.swift</a></pre><h4>Set the messaging delegate</h4><pre>Messaging.messaging().delegate = self</pre><h4>Fetching the current registration token</h4><p>Registration tokens are delivered via the method messaging:didReceiveRegistrationToken:. This method is called generally once per app start with registration token. When this method is called, it is the ideal time to:</p><ul><li>If the registration token is new, send it to your application server.</li><li>Subscribe the registration token to topics. This is required only for new subscriptions or for situations where the user has re-installed the app.</li></ul><pre>InstanceID.instanceID().instanceID { (result, error) in<br>  if let error = error {<br>    print(&quot;Error fetching remote instance ID: \(error)&quot;)<br>  } else if let result = result {<br>    print(&quot;Remote instance ID token: \(result.token)&quot;)<br>    self.instanceIDTokenMessage.text  = &quot;Remote InstanceID token: \(result.token)&quot;<br>  }<br>}</pre><h4>Swizzling disabled: mapping your APNs token and registration token</h4><p>If you have disabled method swizzling, you’ll need to explicitly map your APNs token to the FCM registration token. Override the methods didRegisterForRemoteNotificationsWithDeviceTokento retrieve the APNs token, and then set FIRMessaging&#39;s <a href="https://firebase.google.com/docs/reference/ios/firebasemessaging/api/reference/Classes/FIRMessaging#/c:objc(cs)FIRMessaging(py)APNSToken">APNSToken</a> property:</p><pre>func application(application: UIApplication,<br>                 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {<br>  Messaging.messaging().apnsToken = deviceToken<br>}</pre><h4>Prevent auto initialization</h4><p>FCM generates an Instance ID, which is used as a registration token within FCM. When an Instance ID is generated the library will upload the identifier and configuration data to Firebase.If you want to get an explicit opt-in before using Instance ID, you can prevent generation at configure time by disabling FCM. To do this, add a metadata value to your Info.plist (not your GoogleService-Info.plist):</p><p>FirebaseMessagingAutoInitEnabled = NO</p><p>To re-enable FCM, you can make a runtime call:</p><pre>Messaging.messaging().autoInitEnabled = true</pre><p><strong><em>References</em></strong> :</p><p><a href="https://firebase.google.com/docs/cloud-messaging/ios/client">Set up a Firebase Cloud Messaging client app on Apple platforms</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FA1SDBIViRtE%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DA1SDBIViRtE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FA1SDBIViRtE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/003226d3e13d3f9a2b0d0c3ccd263b7d/href">https://medium.com/media/003226d3e13d3f9a2b0d0c3ccd263b7d/href</a></iframe><p><strong>If you liked this post, please share &amp; give some claps </strong>👏</p><p>iCoder on Implementation :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e5eb16e56e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>