<?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 Jay Savsani on Medium]]></title>
        <description><![CDATA[Stories by Jay Savsani on Medium]]></description>
        <link>https://medium.com/@jaysavsani07?source=rss-c60fc4869871------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*73xvKQ8zYJsd-uQKqfLLiQ.png</url>
            <title>Stories by Jay Savsani on Medium</title>
            <link>https://medium.com/@jaysavsani07?source=rss-c60fc4869871------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 13:59:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jaysavsani07/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[Flutter CI/CD with Github Actions & Fastlane — Part 2(iOS)]]></title>
            <link>https://jaysavsani07.medium.com/flutter-ci-cd-with-github-actions-fastlane-part-2-ios-a4b281921d39?source=rss-c60fc4869871------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4b281921d39</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[fastlane]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Jay Savsani]]></dc:creator>
            <pubDate>Wed, 19 May 2021 16:27:07 GMT</pubDate>
            <atom:updated>2021-05-21T03:01:22.613Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter CI/CD with Github Actions &amp; Fastlane — Part 2(iOS)</h3><p>This is the part 2 of my series on CI/CD for your flutter project. You can check here for <a href="https://jaysavsani07.medium.com/flutter-ci-cd-with-github-actions-fastlane-part-1-android-14473438072d"><strong>part-1</strong></a> for CI/CD on android platform of flutter project.</p><p>If you’ve followed my previous article, I assume that you already have .github/workflow files in your project, otherwise you just need to refer that portion before you proceed further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u41Okfy7LRU8jvNp5xNTkQ.jpeg" /></figure><h3>Let’s Do it.</h3><p>I’m going to divide this setup into following steps.</p><ol><li>Fastlane setup for iOS platform.</li><li>Github repo setup for Fastlane match.</li><li>Fastfile &amp; Appfile setup and details.</li><li>Github secrets.</li><li>Github workflow file setup.</li><li>Upload to TestFlight with Github actions.</li></ol><h4>Step 1 : Fastlane setup for iOS platform</h4><p>Let’s configure Fastlane for your iOS platform. Go to your flutter project and then run this commands</p><pre>cd ios<br>fastlane init</pre><p>Now Fastlane would ask you few questions for your setup. Select option 2 because we want to upload our app on TestFlight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YpSBVVCIKRBHSAXz_tDvWA.png" /></figure><p>In next step, fastlane would ask you for your apple developer credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ycHpB9A3yPaswzwuV17Aw.png" /></figure><p>Fastlane will check if your package name(com.xyz) is available in your Developer Portal or not. If you’re doing it for your fresh app and haven’t registered your App ID just like me then say yes and proceed next. You’ll be prompted to enter an App name and then hit <strong>Enter</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iiht5SWsD_c2bYeDJvOuRQ.png" /></figure><p>So fastlane just created an app for us. You can check it on your App Store connect and you’d find your newly created app. Also your <strong>Fastfile</strong> &amp; <strong>Appfille</strong> will be generated inside ./ios/fastlane/ folder &amp; <strong>Gemfile</strong> inside your ./ios/ root folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*vE3QLjn1SUUXAKEvB7Owew.png" /></figure><p>Open your <strong>Gemfile</strong> and add below code, install this plugin via fastlane install plugin command in your terminal.</p><pre>gem &quot;fastlane-plugin-flutter_version&quot;, git: &quot;<a href="https://github.com/tianhaoz95/fastlane-plugin-flutter-version">https://github.com/tianhaoz95/fastlane-plugin-flutter-version</a>&quot;</pre><p>This plugin helps Fastlane to fetch build’s version code from your <strong>pubspec.yml</strong>. This version_code will be used to create build number of our app.</p><p><em>Note: You may be prompted with some fastlane instruction to modify gem file. Say yes and move ahead, you’ll see a message of “successfully installed plugin”.</em></p><h4>Step 2: Github repo setup for Fastlane match</h4><p>Fastlane is a collection of tools to automate the development &amp; release process, <strong>match</strong> is one of those tools. It’s a new approach iOS &amp; macOS code signing.</p><p>Question :<strong> </strong>How <strong>match</strong> helps you in your iOS setup?</p><p>Answer : When you want to release any iOS app, you generate CA from local machine and then generate all certificates, keys and provision profiles manually on <a href="https://developer.apple.com/">developer.apple.com</a>. Then you’ve to save this certs &amp; profiles secretly somewhere safe on local or cloud. And then assume that you’re working in a team of many developers then you’ve to share this with each of them. <strong>Match </strong>helps you to save from all this manual setup and share your secrets conveniently with your team.</p><p>First you need to create an empty <strong>private</strong> repo on your github account. This will be used by match to save your certificate on this repo. Once you create this repo, now you need to initialise match for iOS app.</p><pre>cd ios<br>fastlane match init</pre><p>match will ask you to provide storage mode where you want to store certificates &amp; profiles. We’ll select the option “git” for cloud storage and provide link as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oKQfxExM_TrL7gAH41XdmQ.png" /></figure><p>A <strong>Matchfile</strong> will be created inside your ./ios/fastlane/ folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*kOQUMCa04VH_9YloI76hHg.png" /></figure><p>Open <strong>Matchfile,</strong> add type(&quot;appstore&quot;)below line type(“development”).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*yq-Mhy0d0V_AJWWa43VXXw.png" /></figure><p>Now we’ll ask match to create distribution certificate for us. So the command would be as below. <em>Note down </em><strong><em>password</em></strong><em> that you enter in this step.</em></p><pre>fastlane match appstore</pre><p>Fastlane would do following things now.</p><ul><li>Create distribution certificate (if not available already).</li><li>Download &amp; install these certificate on your local machine.</li><li>Create matching provisioning profile (if not found).</li><li>Download &amp; install it locally.</li><li>Push these files on your <strong>Github repo</strong>.</li></ul><p>That’s the magic of <strong>match</strong>. You can see this certificates &amp; profiles created on <a href="https://developer.apple.com/account/resources/certificates/list">developer.apple.com</a> on your behalf, also those files are saved on your github repo.</p><p>Lastly, open your Runner.xcworkspace in Xcode, and select the provisioning profile for distribution that we’ve just created. If you can’t find it, login into your xcode first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*pFsB5I0IwQ3EuL3QhHyBAA.png" /></figure><h4>Step 3 : Fastfile &amp; Appfile setup and details</h4><p>Open your Fastfile and comment out everything, replace all with following code.</p><pre># Replace evverything in Fastfile with below code</pre><pre>default_platform(:ios)</pre><pre>APPLICATON_ID = ENV[&quot;APPLICATON_ID&quot;]<br>BUNDLE_IDENTIFIER = ENV[&quot;BUNDLE_IDENTIFIER&quot;]<br>PROVISIONING_PROFILE_SPECIFIER = ENV[&quot;PROVISIONING_PROFILE_SPECIFIER&quot;]<br>TEMP_KEYCHAIN_USER = ENV[&quot;TEMP_KEYCHAIN_USER&quot;]<br>TEMP_KEYCHAIN_PASSWORD = ENV[&quot;TEMP_KEYCHAIN_PASSWORD&quot;]</pre><pre>def delete_temp_keychain(name)<br>  delete_keychain(<br>    name: name<br>  ) if File.exist? File.expand_path(&quot;~/Library/Keychains/#{name}-db&quot;)<br>end</pre><pre>def create_temp_keychain(name, password)<br>  create_keychain(<br>    name: name,<br>    password: password,<br>    unlock: false,<br>    timeout: false<br>  )<br>end</pre><pre>def ensure_temp_keychain(name, password)<br>  delete_temp_keychain(name)<br>  create_temp_keychain(name, password)<br>end</pre><pre>platform :ios do<br>  lane :closed_beta do<br>    keychain_name = TEMP_KEYCHAIN_USER<br>    keychain_password = TEMP_KEYCHAIN_PASSWORD<br>    ensure_temp_keychain(keychain_name, keychain_password)</pre><pre>    match(<br>      type: &#39;appstore&#39;,<br>      app_identifier: &quot;#{BUNDLE_IDENTIFIER}&quot;,<br>      git_basic_authorization: Base64.strict_encode64(ENV[&quot;GIT_AUTHORIZATION&quot;]),<br>      readonly: true,<br>      keychain_name: keychain_name,<br>      keychain_password: keychain_password <br>    )</pre><pre>    gym(<br>      configuration: &quot;Release&quot;,<br>      workspace: &quot;Runner.xcworkspace&quot;,<br>      scheme: &quot;Runner&quot;,<br>      export_method: &quot;app-store&quot;,<br>      export_options: {<br>        provisioningProfiles: { <br>            APPLICATON_ID =&gt; PROVISIONING_PROFILE_SPECIFIER<br>        }<br>      }<br>    )</pre><pre>    pilot( <br>      apple_id: &quot;#{APPLICATON_ID}&quot;,<br>      app_identifier: &quot;#{BUNDLE_IDENTIFIER}&quot;,<br>      skip_waiting_for_build_processing: true,<br>      skip_submission: true,<br>      distribute_external: false,<br>      notify_external_testers: false,<br>      ipa: &quot;./Runner.ipa&quot;<br>    )</pre><pre>    delete_temp_keychain(keychain_name)<br>  end<br>end</pre><p>What this code do, Let me explain you each function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6OJbhFf2BeAHGzx8SVNLqQ.png" /></figure><p><strong>Keychain creation</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tJducNM53LdxsUYM52_ukA.png" /></figure><p><strong>MATCH function</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kzO2P3_y9__KiWLX9dHvuA.png" /></figure><p><strong>Gym Function</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yUm3Wqz86P7ojXSNTU5ACg.png" /></figure><p><strong>Pilot Function</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jJFtp-SVXRUyQU0gzyazDg.png" /></figure><p>Now open your <strong>Appfile</strong> and you should replace your existing code with below code, only if you’re doing it on your open github repo. Skip this incase you’re doing inside your private repo.</p><pre>app_identifier(ENV[&quot;BUNDLE_IDENTIFIER&quot;])<br>apple_id(ENV[&quot;FASTLANE_APPLE_ID&quot;])</pre><pre>itc_team_id(ENV[&quot;ITC_TEAM_ID&quot;])<br>team_id(ENV[&quot;DEVELOPER_PORTAL_TEAM_ID&quot;])</pre><p>As you can see our file already contains all information that we need but it is going to be visible in case of open repo, so we’re just fetching this values from ENV variable instead of adding it directly here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*u8qq8QrbjO76u6ErQDrBBA.png" /></figure><p><strong>Step 4 : Github Secrets</strong></p><p>Now we’re going to configure all ENV variables inside our github secrets.</p><ol><li>APPLICATION_ID is apple id of your application. You can get it from<br>App Store Connect &gt; App Information &gt; General Information &gt; Apple Id</li><li>BUNDLE_IDENTIFIER is just your bundle identifier like com.nividata.expense_manager for me.</li><li>PROVISIONING_PROFILE_SPECIFIER is what you selected in your xcworkspace provisioning profile. It would be like “match AppStore com.nividata.expense_manager”</li><li>TEMP_KEYCHAIN_USER any username that would be used to install certs on virtual machine.</li><li>TEMP_KEYCHAIN_PASSWORD any password that would be used to install certs</li><li>GIT_AUTHORIZATION is used to give access of your github certificate repo to match. It’s a Personal access tokens of your Github. To generate it<br>Github &gt; Your Profile &gt; Settings &gt; Developer Settings &gt; Personal access tokens. Now you need to save it as &lt;github_username&gt;:&lt;personal_access_token&gt;. So mine looked like below “<strong>jaysavsani07:ghp_imnotgoingtodeclaremytokenhere</strong>”</li><li>FASTLANE_APPLE_EMAIL_ID is email id you used to manage this app, or while creating all match certificates.</li><li>ITC_TEAM_ID you’ll get it from Appfile itself. If not login into your developer account and go to this <a href="https://appstoreconnect.apple.com/WebObjects/iTunesConnect.woa/ra/user/detail">link</a>, contentProviderId is your ITC_TEAM_ID.</li><li>DEVELOPER_PORTAL_TEAM_ID is your team id. You can get it under MEMBERSHIP &gt; Team ID</li><li>MATCH_PASSWORD is password that you used during match setup. This will be used to decrypt certificate.</li><li>APP_SPECIFIC_PASSWORD needed by Fastlane to upload your build on your behalf. You can generate it by following this <a href="https://support.apple.com/en-in/HT204397"><em>steps</em></a>.</li></ol><p>Your github secret should look something like this screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mDTW08_58068lJ0kWKsrrg.png" /></figure><p><strong>Step 5 : Github workflow file setup.</strong></p><p>Create a file named <strong>ios-deploy.yml</strong> inside your ./github/workflows/ and add the following code inside your file</p><pre>name: Appstore Deployment<br>on:<br>  push:<br>    tags:<br>      - master<br>      <br>jobs:<br> deploy_ios:<br>    name: Deploy build to TestFlight<br>    runs-on: macOS-latest<br>    steps:<br>      - name: Checkout code from ref<br>        uses: actions/checkout@v2<br>        with:<br>          ref: ${{ github.ref }}<br>      - name: Run Flutter tasks<br>        uses: subosito/flutter-action@v1<br>        with:<br>          flutter-version: &#39;2.0.6&#39;<br>      - run: flutter clean<br>      - run: flutter pub get<br>      - run: flutter build ios --release --no-codesign<br>      - name: Deploy iOS Beta to TestFlight via Fastlane<br>        uses: maierj/fastlane-action@v1.4.0<br>        with:<br>          lane: closed_beta<br>          subdirectory: ios<br>        env:<br>          ITC_TEAM_ID: &#39;${{ secrets.ITC_TEAM_ID }}&#39;<br>          APPLICATON_ID: &#39;${{ secrets.APPLICATON_ID }}&#39;<br>          BUNDLE_IDENTIFIER: &#39;${{ secrets.BUNDLE_IDENTIFIER }}&#39;<br>          DEVELOPER_PORTAL_TEAM_ID: &#39;${{ secrets.DEVELOPER_PORTAL_TEAM_ID }}&#39;<br>          FASTLANE_APPLE_ID: &#39;${{ secrets.FASTLANE_APPLE_EMAIL_ID }}&#39;<br>          FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: &#39;${{ secrets.APP_SPECIFIC_PASSWORD }}&#39;<br>          MATCH_PASSWORD: &#39;${{ secrets.MATCH_PASSWORD }}&#39;<br>          GIT_AUTHORIZATION: &#39;${{ secrets.GIT_AUTHORIZATION }}&#39;<br>          PROVISIONING_PROFILE_SPECIFIER: &#39;${{ secrets.PROVISIONING_PROFILE_SPECIFIER }}&#39;<br>          TEMP_KEYCHAIN_PASSWORD: &#39;${{ secrets.TEMP_KEYCHAIN_PASSWORD }}&#39;<br>          TEMP_KEYCHAIN_USER: &#39;${{ secrets.TEMP_KEYCHAIN_USER }}&#39;</pre><p><strong>Step 6 : Upload to TestFlight with Github actions.</strong></p><p>Before you proceed for this step, just go to your Runner.xcworkspace and build your app locally to check if you’re not getting any error.</p><p>Commit every file and push it on your master branch and go to your actions tab to check your workflow. If everything goes well then you’ll see your build in your TestFlight with status “processing”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*57osNX5U9hy9AI9KNoY_lQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MOUUNIWXKkkzOZ8_ZHZVrw.png" /></figure><p>Conclusion : In this series of article I tried to keep workflow file &amp; Fastfile as simple as possible. You can find many actions in github <a href="https://github.com/marketplace?type=actions">marketplace</a> and can integrate into your flow as you need. Similarly you can leverage many features of Fastlane like automating screenshots, metadata, release notes etc. But I assume at the end of this two article, you’d be able to deploy your flutter app on both Playstore &amp; Appstore.</p><p>If you face any query regarding any steps, feel free to comment. I’ll always happy to help.</p><p>I’ve implemented this complete flow in one of my open source app <strong>Expense-Manager.</strong></p><p><strong>Github repo</strong> : <a href="https://github.com/jaysavsani07/expense-manager">https://github.com/jaysavsani07/expense-manager</a></p><p><strong>Android App : </strong><a href="https://play.google.com/store/apps/details?id=com.nividata.expense_manager">https://play.google.com/store/apps/details?id=com.nividata.expense_manager</a></p><p><strong>iOS App : </strong><a href="https://apps.apple.com/us/app/expense-manager-money-saver/id1556849821">https://apps.apple.com/us/app/expense-manager-money-saver/id1556849821</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4b281921d39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter CI/CD with Github Actions & Fastlane — Part 1(Android)]]></title>
            <link>https://jaysavsani07.medium.com/flutter-ci-cd-with-github-actions-fastlane-part-1-android-14473438072d?source=rss-c60fc4869871------2</link>
            <guid isPermaLink="false">https://medium.com/p/14473438072d</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[fastlane]]></category>
            <category><![CDATA[continous-integration]]></category>
            <dc:creator><![CDATA[Jay Savsani]]></dc:creator>
            <pubDate>Mon, 17 May 2021 10:57:27 GMT</pubDate>
            <atom:updated>2021-05-21T02:28:59.372Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter CI/CD with Github Actions &amp; Fastlane — Part 1(Android)</h3><p>Publishing your Android &amp; iOS build manually on store is often a tedious and time consuming task. On top of that it affect your productivity because you’re spending lots of hours doing same repetitive tasks. I’ve had lot of struggle implementing CI/CD on my flutter project with Github actions due to lack of good articles so I thought to have an article with complete steps to add CI/CD in your flutter project. I’ve been using Github actions and Fastlane for my native projects since long and now also doing same for my flutter projects.</p><p>This article will cover all the nitty gritty details to implement CI/CD into your flutter project with help of Github Actions &amp; fastlane. This is going to be a series of two articles, current article will cover steps to perform CI/CD for your flutter Android apps and to build and deploy app on Playstore. You can check same setup on my app Expense-Manager on <a href="https://github.com/jaysavsani07/expense-manager"><strong>Github</strong></a><strong>.</strong></p><p>At the end of this two articles, you’ll be able to launch your flutter app on both Playstore &amp; Appstore with Github actions.</p><p>This article is for you if you’re</p><ul><li>Flutter developer, want to integrate CI/CD in your project.</li><li>Don’t have any previous knowledge on implementing CI/CD for mobile apps.</li><li>Don’t have any previous experience on Github Actions or Fastlane.</li></ul><p><strong>Prerequisites</strong></p><ul><li>git cli</li><li>fastlane cli</li><li>GnuPG cli (<a href="https://gnupg.org/download/">download</a> here) `gpg` command should work in your terminal.</li></ul><p>Note: I’m going to cover every details of Github Actions and Fastlane that we’re going to use in this setup. So it’d be better if you know a bit about github action’s details like jobs, workflow and few commands of Fastlane as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u41Okfy7LRU8jvNp5xNTkQ.jpeg" /></figure><h3><strong>Let’s Do it.</strong></h3><p>We’ll do it for ANDROID platform first. I’ve divided this process into six steps.</p><ol><li>Fastlane setup for Android platform.</li><li>Configuration of Project on Google cloud console and Playstore.</li><li>Encryption of jks, properties &amp; service_account_key.json file.</li><li>Write decryption script for the files of step 3.</li><li>Setup of Github workflow file.</li><li>Upload APK on playstore with github actions.</li></ol><h4>Step 1 : Fastlane setup for Android platform</h4><p>Let’s setup Fastlane inside your flutter project. Hope you’ve already downloaded fastlane CLI. Go to your flutter project and then</p><pre>cd android<br>fastlane init</pre><p><em>Explanation: This will create </em><strong><em>fastlane</em></strong><em> folder insider your</em><strong><em> ./android</em></strong><em> root folder.</em></p><p>Now fastlane will ask you for your package name which I’ve highlighted in below screenshot. Enter your package name and hit<strong> next</strong>↵.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*WmLhRWSsnS6yUiOAC5FkSg.png" /></figure><p>Okay, Now you might get an output like below screenshot. Fastlane is asking you for path of “json secret file”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*j8XbudSyG4pWrSUcX3pJRg.png" /></figure><p><strong>Question</strong> : What’s this secret json file?</p><p><strong>Answer</strong> : hmm, so we want our APK to be deployed automatically on our play store right. But how would fastlane know where to upload this APK, On whose account? By providing this secret file to fastlane, we’re giving necessary information &amp; permission to fastlane to upload APK on our play console. But we’ll skip adding secret file right now. We can add it anytime later on.(In step 3). Hit <strong>Enter↵.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*ORz_qTf0-hpu7JYaw6nm4Q.png" /></figure><p>Fastlane is asking whether you want to add metadata, screenshots and builds!!. We’ll just say “no” for now. Hit <strong>Enter↵</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*hRk1Hbj3Tfisi1RjQwkN8A.png" /></figure><p>You can see two files <strong>Fastfile</strong> &amp; <strong>Appfile</strong> created inside ./fastlane folder and <strong>Gemfile</strong> inside ./android root directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*ShIX93xZJp8tvDG-QgmRHQ.png" /></figure><p>Open <strong>Gemfile</strong> in any editor and add following plugin.</p><pre>gem &quot;fastlane-plugin-flutter_version&quot;, git: &quot;<a href="https://github.com/tianhaoz95/fastlane-plugin-flutter-version">https://github.com/tianhaoz95/fastlane-plugin-flutter-version</a>&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*MtFxep_dAAoHCgpmjH9r6w.png" /></figure><p>This plugin helps Fastlane to fetch build’s version code from your flutter’s “pubspec.yml” . This version_code will be used to create build number on play console while deployment. Now install plugin by running following command inside ./android/fastlane directory.</p><pre>fastlane install_plugins</pre><p><em>Note: You may be prompted with some fastlane instruction to modify gem file. Say yes and move ahead, you’ll see message of successful plugin installation.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*lWp_jS5boM1rC-ntLxEMKg.png" /></figure><p>Now open <strong>Fastfile</strong> and copy paste below code</p><pre>default_platform(:android)</pre><pre>platform :android do<br>  desc &quot;Deploy to closed beta track&quot;<br>  lane :closed_beta do<br>    begin<br>      gradle(task: &quot;clean&quot;)<br>      gradle(<br>        task: &quot;bundle&quot;,<br>        build_type: &#39;Release&#39;<br>      )<br>      upload_to_play_store(<br>        track: &#39;beta&#39;,<br>        aab: &#39;../build/app/outputs/bundle/release/app-release.aab&#39;,<br>        skip_upload_metadata: true,<br>        skip_upload_images: true,<br>        skip_upload_screenshots: true,<br>        release_status: &quot;draft&quot;,<br>        version_code: flutter_version()[&quot;version_code&quot;],<br>      )<br>    end<br>  end<br>end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*c7Y_-Q7ZQk93n9m1dlDLCw.png" /></figure><p>Fastlane helps us with too many options like uploading builds, adding screenshots, images, track promotion, metadata, release notes etc. To keep everything simple we’re just going to upload our aab/apk with Fastlane.</p><h4>Step 2 : Configuration of Project on Google cloud console and PlayStore</h4><p>Remember we skipped step of <strong>secret_json</strong> file while setting up Fastlane. We need to provide that file to Fastlane, it’s like an address on envelope. So Fastlane would know where to deliver that build.</p><p><strong>secret_json</strong> is a Google Developers Service Account Key which will be used for authentication of requests made to <a href="https://developers.google.com/android-publisher">Google Play Developer API</a>. Then Fastlane could establish a connection to this API to publish our app to Google Playstore.</p><p>Now Open <a href="https://play.google.com/console/"><strong>Google Play Console</strong></a><strong> </strong>go to <strong>Settings &gt; Developer Account &gt; API Access </strong>and link your cloud console project with play console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KSjV5GiXJLu4ggf9v_ukcQ.png" /></figure><p>Note: If you find difficulty with linking project, Then go to Linked Accounts &gt; Firebase Project and link your project there first.</p><p>Once you linked your cloud console project (or firebase project) you’ll see something like below screenshot or an empty screen to create service account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i1eYbIhusDth_sm6wecZKA.png" /></figure><p>Now let’s create Service Account. Go to your Google Cloud &gt; IAM &amp; Admin &gt; Service Accounts &gt; Select Your Project &gt; “CREATE SERVICE ACCOUNT”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*szBembTxR4nUvewOft5z2w.png" /></figure><p>On step 2 you should grant access to this account via selecting option for role as a “service account admin” or “basic”. Once your service account has been created, go to “keys” and click “create new key”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UgrQpJTLOoq7Kz9tyFn3BQ.png" /></figure><p>Select file type `json` and a json file will be downloaded on your PC. <strong>Copy It somewhere safe. </strong>You won’t be able to download same via console again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UU5YNV04gZ7EpEUwcC9V3A.png" /></figure><p>Go back to your “<strong>Play Console</strong>” and “Refresh service account”. Your newly created service account should be added in last position.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_U_efMg1xAJFvryEYqxddw.png" /></figure><p>Click on “grant Access” for that service account, and allow an app that you are configuring for CI/CD flow. If you are doing it for a fresh app then you also need to create an app first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Simzcl9Anv1GCsWKlUm4mA.png" /></figure><p>Open your ./android/fastlane/Appfile and add the name of downloaded json file. I’ve named it as “service_account_key.json”.</p><pre>json_key_file(&quot;service_account_key.json&quot;)<br>package_name(&quot;com.nividata.expense_manager&quot;)</pre><h4>Step 3 : Encryption of jks, properties &amp; service_account_key.json file</h4><p>I’m going to use public Github repo for my project, so our keystore.jks, key.properties and service_account_key.json file should not be placed directly in our Github project. We’re going encrypt this files and add it at runtime of build. Keep this files handy before you proceed for this step.</p><ol><li>key.jks (you can use keytool to generate it, if not present already)</li><li>key.properties (ideally located in root ./android/key.properties)</li><li>service_account_key.json (that we got from google cloud console, Step 2)</li></ol><p>Check in your app/build.gradle for the following lines for key.properties file. If not present, then add it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OU1xHiJiMWyyFueroUWEHA.png" /></figure><p>Create key.properties and add following code</p><pre>storePassword={storePassword}<br>keyPassword={keyPassword}<br>keyAlias={keyAlias}<br>storeFile=../{key_name}.jks</pre><pre>#you need to fill values of password, alias and .jks file name</pre><p>compress and make a zip of this 3 file and name it as <strong>key_files.zip</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*EbETfwDhi9zEFrlyMM3VNQ.png" /></figure><p>Now let’s encrypt this file with help of GnuPG</p><pre>gpg --symmetric --cipher-algo AES256 key_files.zip</pre><p>You’ll be prompted with a dialog for password, remember this password because it’ll be used to decrypt the same file. Now you’ll have an encrypted file named as <strong>key_files.zip.gpg. </strong>See the graphical representation below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*ARBTKMUOvFLgUDKUlIEXbg.png" /></figure><p>Now copy this key_files.zip.gpg into your flutter projects ./android root directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*iUTx8vJ24liB555cy9jvVw.png" /></figure><h4>Step 4 : Write decryption script for the files of step 3</h4><p>Okay, so we’ve encrypted zip file at android/key_files.zip.gpg, we’re going to follow this steps via shell scripts to decrypt it on remote machine.</p><ul><li>decrypt key_files.zip.gpg and get our <strong>key_files.zip</strong></li><li>unzip key_files.zip and get .jks, key.properties and service_account_key.json</li></ul><pre>#!/bin/sh<br># --batch to prevent interactive command<br># --yes to assume &quot;yes&quot; for questions</pre><pre>gpg --quiet --batch --yes --decrypt --passphrase=&quot;$ANDROID_KEYS_ZIP_PASSPHRASE&quot; \<br>--output android/key_files.zip android/key_files.zip.gpg &amp;&amp; cd android &amp;&amp; jar xvf key_files.zip &amp;&amp; cd -</pre><pre>ls -d $PWD/android/*<br># mv ./android/expensemanager.jks ./android/app<br># move your file according to path in key.properties</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*zzSQI42MyE-kR-Ugk-sYMg.png" /></figure><p>Go to Github &gt; Settings &gt; Secrets &gt; New Repository Secret <br>Name = ANDROID_KEYS_ZIP_PASSPHRASE,<br>Value = “password of zip file you’ve used while gpg encryption”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rdMsPApU5q3fUZWcPkc6UA.png" /></figure><h4>Step 5 : Setup of Github workflow file</h4><p>In this step we’re going to create workflow file for github actions. I’m not going deeper in this article about workflow files and their commands but you can refer this <a href="https://medium.com/intelligentmachines/github-actions-basics-40a4d9b417f8">article</a> for basic understanding.</p><p>Create a file named android-deploy.yml inside ./.github/workflows/ and paste below code.</p><pre>name: Playstore deployment</pre><pre>on:<br>  push:<br>    branches:<br>      - master</pre><pre>jobs:<br>  #CI<br>  build_android:<br>    name: Building Android <br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v2<br>      - name: Setup Java<br>        uses: actions/setup-java@v1<br>        with:<br>          java-version: 12.x<br>      - name: Decrypt Android keys<br>        run: sh ./.github/scripts/decrypt_android_secrets.sh<br>        env:<br>          ANDROID_KEYS_SECRET_PASSPHRASE: ${{ secrets.ANDROID_KEYS_SECRET_PASSPHRASE }}<br>      - name: Setup Flutter<br>        uses: subosito/flutter-action@v1<br>        with:<br>          flutter-version: 2.0.1<br>      - name: Install Flutter dependencies<br>        run: flutter pub get<br>        # Add build runner commands here if you have any<br>      - name: Build the APK<br>        run: flutter build apk --release<br>      - name: Upload artifact to Github<br>        uses: actions/upload-artifact@v1<br>        with:<br>          name: release-apk<br>          path: build/app/outputs/apk/release/app-release.apk<br></pre><pre>  #CD<br>  deploy_android:<br>    name: Deploying to playstore<br>    runs-on: ubuntu-latest<br>    needs: [build_android]<br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v2<br>      - name: Setup Java<br>        uses: actions/setup-java@v1<br>        with:<br>          java-version: 12.x<br>      - name: Decrypt Android keys<br>        run: sh ./.github/scripts/decrypt_secret.sh<br>        env:<br>          ANDROID_KEYS_ZIP_PASSPHRASE: ${{ secrets.ANDROID_KEYS_ZIP_PASSPHRASE }}<br>      - name: Setup Flutter<br>        uses: subosito/flutter-action@v1<br>        with:<br>          flutter-version: 2.0.6<br>      - run: flutter pub get<br>      - run: flutter build apk --release<br>      - name: Upload artifact to Github<br>        uses: actions/upload-artifact@v1<br>        with:<br>          name: release-apk<br>          path: build/app/outputs/apk/release/app-release.apk<br>      - name: Run Fastlane<br>        uses: maierj/fastlane-action@v1.4.0<br>        with:<br>          lane: closed_beta<br>          subdirectory: android</pre><p>Now commit it and push it into master branch, if everything goes correct then it’ll start building your app and then try to upload app on playstore, with <strong>failure</strong>. Yes, I bet you already have faced &amp; fixed too many errors before coming to this step :) . You’re likely to see something like below screenshot in your actions.<br><em>Note : You can completely ignore first job, it’s just to generate &amp; upload APK to artifacts. You can combine it with second job easily.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9d5g1H-p9xzUrRyIjqtGWg.png" /></figure><p>Okay so we built an APK successfully but failed to upload it on Playstore because Fastlane is throwing an error saying that <strong><em>no package found on playstore</em></strong>. Yes we haven’t created or registered any app on Play console right.<br>You do not need Step 6 if you are configuring CI/CD for an app which is already deployed on store.</p><h4>Step 6 : Upload on playstore with workflow</h4><p>Last step would be to register our app on Google play console and upload a build manually for the first time. Yes, you heard it correct, upload it manually for first time. Because Fastlane would throw an error of package not found if we do not register package name initially.</p><p><em>There is a way that you can do everything via Fastlane without uploading first build manually, but that would be too much for beginners who don’t know anything about Fastlane. If you already know bit about Fastlane then you already know how to do this.</em></p><p>Go to your play console and create an app with name and other information. Once done, download the APK from artifacts and just drop that APK on your console in open / close track.</p><p>Go back to Github Repo &gt; Action &gt; Select last failed workflow &gt; Re-run jobs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KpJ4Go8k8i6eYZR2CZwkAg.png" /></figure><p>And Yesssss, Voila !!! You’ve successfully deployed your app on playstore with Github Actions &amp; Fastlane.</p><p><em>Note: I tried to keep workflow and fastlane file as simple as possible, but you can configure in your own way like formating codes, running test cases before making release build. You can completely remove first job from above workflow file because it’s not needed unless you’re doing mentioned things or not want to upload APK file. Fastlane is very powerful tool, you can also experiment with Fastfile for uploading screenshots, metadata, release notes etc.</em></p><p>This CI/CD steps belongs to one of our flutter app named “<strong>Expense-Manager</strong>” &amp; I’ve deployed both <a href="https://play.google.com/store/apps/details?id=com.nividata.expense_manager">Android</a> &amp; <a href="https://apps.apple.com/us/app/expense-manager-money-saver/id1556849821">iOS</a> app on their respective store with Github actions. This app Expense-Manager is available on our open repository on <a href="https://github.com/jaysavsani07/expense-manager"><strong>Github</strong></a>. You can check workflow files and Fastlane setup files there as well.</p><p>If you find any query during setup of CI/CD in your flutter app following above steps, drop your comments below. Always happy to help.</p><p>You can check <a href="https://jaysavsani07.medium.com/flutter-ci-cd-with-github-actions-fastlane-part-2-ios-a4b281921d39"><strong>part-2</strong></a> in this series, which covers CI/CD flow for your flutter iOS apps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14473438072d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Cast iOS(Swift) Sender App]]></title>
            <link>https://medium.com/macoclock/google-cast-ios-swift-sender-app-46ee98cadaf7?source=rss-c60fc4869871------2</link>
            <guid isPermaLink="false">https://medium.com/p/46ee98cadaf7</guid>
            <category><![CDATA[iphone]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[Jay Savsani]]></dc:creator>
            <pubDate>Sat, 29 Feb 2020 12:44:07 GMT</pubDate>
            <atom:updated>2020-03-06T05:21:35.824Z</atom:updated>
            <content:encoded><![CDATA[<h4>iOS sender App for Google Cast MediaControl Overview</h4><p>This is the second article in a series of 3 where I’ll show you how to add media control while your iOS app is having an active cast session. You can read my previous <a href="https://medium.com/@jay.savsani07/google-cast-in-ios-swift-sender-app-24254e6ce507"><strong>article</strong></a> about basic integration for iOS sender App of Google cast <a href="https://medium.com/@jay.savsani07/google-cast-in-ios-swift-sender-app-24254e6ce507"><strong>here</strong></a>. I’m assuming that you’ve gone through the previous article and have bare minimum code that can cast a video to Chrome Cast. Now that we are able to Cast Video, how we can show <strong>Big and Small media controller</strong> inside our App like Netflix does(adding screenshot below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQE9FfXIMdRgmsP0s_D0DQ.jpeg" /></figure><h3>Expanded Media Controller</h3><p>It’s super easy to open Expanded media controller in sender App. Google Cast provides a simple method that you can use to open this controller. Add below code after your line where you’ve loaded your cast request.</p><pre>GCKCastContext.sharedInstance().presentDefaultExpandedMediaControls()</pre><p>So your code block will look something like this after you’ve added media controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*BVMP8TqYNIQprWKvc2Urfg.png" /></figure><p>Now, cast any video and you’ll be able to see Expanded media controller like this screenshot. It’s a default controller provided by Google Cast. You can customise this controller as per your requirement by referring to the official documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*8WASUeIrg3P2wBMtzjqf3g.png" /></figure><h3>Mini Media Controller</h3><p>As per the design checklist by Google Cast, a sender app should provide a persistent control known as the <a href="https://developers.google.com/cast/docs/design_checklist/sender#mini-controller">mini controller</a> that should appear when the user navigates away. However, it completely depends on your priority/choice where you want to show it or hide it. There&#39;s two way how we can add this mini media controller.</p><ul><li><strong>Option 1: Let the Cast framework manage the layout of the mini controller by wrapping your existing view controller with its own view controller.</strong> For achieving this you need to attach a mini media view controller to your <strong>Navigation Controller.</strong></li><li><strong>Option 2: Manage the layout of the mini controller widget yourself by adding it to your existing view controller by providing a subview in the storyboard.</strong> By choosing this option you’re free to add mini media controller to any of your existing view controller by adding it as <strong>subview.</strong></li></ul><h4>Option 1: Wrapping up into existing view controller</h4><p>Inside your <strong>app delegate</strong>, get instance your navigation controller (not view controller) and let Google Cast SDK take over all things for attaching mini media controller.</p><pre><br>let appStoryboard = UIStoryboard(name: &quot;Main&quot;, bundle: nil)<br>let navigationController = appStoryboard.instantiateViewController(withIdentifier: &quot;MainNavigation&quot;)</pre><pre>let castContainerVC =         GCKCastContext.sharedInstance().createCastContainerController(for: navigationController)<br>  castContainerVC.miniMediaControlsItemEnabled = true<br>  window = UIWindow(frame: UIScreen.main.bounds)<br>  window!.rootViewController = castContainerVC<br>  window!.makeKeyAndVisible()</pre><p>Now, this code looks really simple and easy but what if you don’t want to add mini media to your main navigation. What if you’ve multiple storyboard and your navigation controller are different. What if you’ve TabView. This flow is bit complicated and you’d certainly not like to add it directly to your main navigation.</p><h4><strong>Options 2: Add as a Subview</strong></h4><p>You can also add a mini media controller as a subview inside any view controller, which you’d find more elegant compare to option 1. create two variable inside your view controller as below</p><pre><strong>private</strong> <strong>var</strong> miniMediaControlsViewController: GCKUIMiniMediaControlsViewController! </pre><pre><strong>var</strong> mediaView: UIView!</pre><p>and inside <strong>viewDidLoad </strong>add this mediaView programmatically</p><pre>mediaView = UIView(frame: CGRect(x: 0, y: <strong>self</strong>.view.frame.height - 70 - (UIApplication.shared.keyWindow?.safeAreaInsets.bottom)!, width: <strong>self</strong>.view.frame.width, height: 70))</pre><pre><strong>self</strong>.view.addSubview(mediaView!)</pre><p>Now time to create mini media view controller and adding it to an existing view controller and install it as a container view into an existing view controller</p><pre><strong>let</strong> castContext = GCKCastContext.sharedInstance()</pre><pre>sessionManager.add(<strong>self</strong>)</pre><pre>miniMediaControlsViewController = castContext.createMiniMediaControlsViewController()<br>miniMediaControlsViewController.delegate = <strong>self</strong></pre><pre>installViewController(miniMediaControlsViewController, inContainerView: mediaView!)</pre><pre><strong>func</strong> installViewController(<strong>_</strong> viewController: UIViewController?, inContainerView containerView: UIView) {</pre><pre><strong>  if</strong> <strong>let</strong> viewController = viewController {</pre><pre>    addChild(viewController)<br>    viewController.view.frame = containerView.bounds<br>    containerView.addSubview(viewController.view)<br>    viewController.didMove(toParent: <strong>self</strong>)</pre><pre>  }</pre><pre>}</pre><p>Now your code block would look something like below screenshot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*dRfkqJpN8tOwzQUqf5hUpg.png" /></figure><p>You can control the visibility of mini-media controller base on your need. <strong>updateControlBarVisibility </strong>method is used to maintain visibility of the controller. Now run the app and start casting. It’ll give you mini media like below screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*ldDnLPPbylK9ndQcwan-bw.png" /></figure><p>Okay !! So now your app is fully qualified as per Google Cast Checklist of sender app. You can customise the UI of the controller as per your need exploring Google Cast SDK.</p><p>I’m concluding this article here and adding <a href="https://github.com/jaysavsani07/Google-Cast-Demo"><strong>Github</strong></a> link of this project. You can clone it and play around it via modifying code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46ee98cadaf7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/macoclock/google-cast-ios-swift-sender-app-46ee98cadaf7">Google Cast iOS(Swift) Sender App</a> was originally published in <a href="https://medium.com/macoclock">Mac O’Clock</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Cast in iOS(Swift) Sender App]]></title>
            <link>https://medium.com/macoclock/google-cast-in-ios-swift-sender-app-24254e6ce507?source=rss-c60fc4869871------2</link>
            <guid isPermaLink="false">https://medium.com/p/24254e6ce507</guid>
            <category><![CDATA[iphone]]></category>
            <category><![CDATA[google-cast]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[chromecast]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jay Savsani]]></dc:creator>
            <pubDate>Sat, 29 Feb 2020 06:09:58 GMT</pubDate>
            <atom:updated>2021-05-09T04:20:33.778Z</atom:updated>
            <content:encoded><![CDATA[<p>iOS Google Cast sender App using SDK by Google (Tested on iOS 13 &amp; 12) developed in Swift 5.x</p><p>This article is for developers who are looking for integrating Google Cast into their exiting application or want to learn how Google Cast works. Integrating Google Cast seems very straight forward from their <a href="https://developers.google.com/cast/docs/ios_sender">documentation</a> but still, you’ll find many headaches while integrating it into your existing application like how to show <strong>mini media controller</strong> and how to add a controller to your <strong>TabView</strong> kind of application.</p><p>This is going to be a series of 3 articles, this article will walk you through <strong>basic integration</strong> of Google Cast SDK into iOS SDK. In the second <a href="https://medium.com/@jay.savsani07/google-cast-ios-swift-sender-app-46ee98cadaf7"><strong>article</strong></a> I’ll walk you through how to show media controller and in the last article we’ll learn about how to customise view controller according to your app theme.</p><h3>Create New Xcode Project &amp; Install Pod</h3><p>Now you need to create a new Xcode project and use <strong>pod init</strong> to generate pod file. Now add we’re going to use <strong>no Bluetooth Google Cast SDK</strong> for iOS13. By adding no Bluetooth we’re just leaving Guest mode out of our application. If you want more details on Guest Mode you can find out in this <a href="https://support.google.com/chromecast/answer/6109292?hl=en-IN">article</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d84003df34747a76277423e8c37cb83e/href">https://medium.com/media/d84003df34747a76277423e8c37cb83e/href</a></iframe><p>Now go with</p><pre>pod install</pre><p>and you’ll have Google Cast SDK inside your project. Open <em>Google Cast Demo.xcworkspace. </em>Now open your <strong><em>AppleDelegate.swift </em></strong>and add following lines inside <strong>didFinishLaunchingWithOptions</strong>. This will start discovering available Casting devices inside your network with options that you’re providing. <strong>kReceiverAppID</strong>, is the default id for receiver app provided by the framework. <em>You can also create Cast Receiver app for customising receiver app’s styling (like Netflix, Prime Videos).</em></p><pre><strong>let</strong> criteria = GCKDiscoveryCriteria(applicationID: kReceiverAppID)<br><strong>let</strong> options = GCKCastOptions(discoveryCriteria: criteria)<br>GCKCastContext.setSharedInstanceWith(options)<br>GCKLogger.sharedInstance().delegate = <strong>self</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*_k3066lbzfHeZRaPFlVplQ.png" /></figure><h3>Cast Button inside Navigation Bar</h3><p>Now we’re going to add this cast button to our navigation bar. You can add this cast button as per your convenience, inside <strong>any other view</strong> apart from navigation view. As you can see in documentation <strong>GCKUICastButton </strong>is an extension of <strong>UIButton</strong> only.</p><pre>let castButton = GCKUICastButton(frame: CGRect(x: 0, y: 0, width: 24, height: 24))<br>castButton.tintColor = UIColor.gray<br>navigationItem.rightBarButtonItem = UIBarButtonItem(customView: castButton)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*CbZCAxxoyyta4-5mmAYvoA.png" /></figure><p>Now you can see Cast button inside the navigation bar. <strong>This cast button will only appear if there’s any Chrome cast available in your network</strong>. It’ll be <strong><em>shown/hidden</em></strong> automatically based on the availability of Chrome cast inside your network.</p><p>Now click that Cast button and Voila!! It’ll show you Chrome cast which is available in your network. In my case, it’s <strong>Bedroom TV. </strong>Now select available Chrome cast and Cast icon will be <strong>turned into a connected one</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J0eqdfwmaPy__HC89wFbKg.png" /></figure><h3>Cast Video on Chrome Cast</h3><p>Now it’s time to cast video on your Chrome cast. For Video and it’s information I’m using google’s <a href="https://gist.github.com/jaysavsani07/019da95c9d54055bebe6c3500f5a4a36"><strong>sample file</strong></a> which they’ve used in their <a href="https://github.com/googlecast/CastVideos-ios">demo</a>. You can find it’s location inside <a href="https://github.com/jaysavsani07/Google-Cast-Demo.git"><strong>project</strong></a>, labeled as sample.json. I’m displaying this video’s inside TableView Controller and have used <strong>SwiftyJSON</strong> for parsing JSON.</p><h4>Preparing Request For Chrome Cast</h4><p>Now the first thing will be providing proper URL for casting to Chrome cast.</p><pre><strong>let</strong> url = URL.init(string: &quot;URL_OF_YOUR_VIDEO&quot;)<br><strong>guard</strong> <strong>let</strong> mediaURL = url <strong>else</strong> {<br>   print(&quot;invalid mediaURL&quot;)<br>   <strong>return<br></strong>}</pre><h4>Providing Metadata to Chrome Cast</h4><p>You can provide metadata to Chrome Cast via like title, thumbnail and description. It’s completely optional what metadata you’d like to provide for casting. You can find a complete list of <a href="https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_media_metadata"><strong>metadata</strong></a> that cast SDK provides.</p><pre><strong>let</strong> metadata = GCKMediaMetadata()<br>metadata.setString(movieModel!.desc, forKey: kGCKMetadataKeyTitle)</pre><pre>metadata.setString(movieModel!.desc, forKey: kGCKMetadataKeySubtitle)</pre><pre>metadata.addImage(GCKImage(url: URL(string: &quot;https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg&quot;)!, width: 480, height: 360))</pre><h4>Creating Request</h4><p>Now that we’ve <strong>URL and Metadata</strong>, it’s time to cast video. For that, we’ll use <strong>GCKMediaInformationBuilder &amp; GCKMediaInformation </strong>and provide URL and metadata to that class.</p><pre><strong>let</strong> mediaInfoBuilder = GCKMediaInformationBuilder.init(contentURL: mediaURL)<br>mediaInfoBuilder.streamType = GCKMediaStreamType.none;<br>mediaInfoBuilder.contentType = &quot;video/mp4&quot;<br>mediaInfoBuilder.metadata = metadata; \\(providing metadata)</pre><pre><strong>let</strong> mediaInformation = mediaInfoBuilder.build() </pre><pre>// Now finally handing over all information and load video<br><strong>if</strong> <strong>let</strong> request =  sessionManager.currentSession?.remoteMediaClient?.loadMedia(mediaInformation){<br>   request.delegate = <strong>self  \\</strong>extend GCKRequestDelegate for this<strong><br></strong>}</pre><p>Inside of Class declare sessionManager variable and use <strong>ViewDidLoad </strong>to get a session to which we’re connected in the previous screen.</p><pre><strong>var</strong> sessionManager: GCKSessionManager!<br>override ViewDidLoad(){<br>    sessionManager = GCKCastContext.sharedInstance().sessionManager<br>}</pre><p>Now your complete code block should look like something below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ul-e2VbbJcaT0faqyoIKuA.png" /></figure><p>Click on <strong>docPlay</strong> method and Done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BMMyf99KlbX0ZPhbuqPlIQ.jpeg" /></figure><p>You can see <strong>Thumbnail, Title and Description that we’ve provided in mediaInformation.</strong></p><p>Now that you’ve played the video to your Casting device and you made <strong>Google Cast sender App for iOS</strong>, To keep things simple, I’m concluding this article here. <a href="https://github.com/jaysavsani07/Google-Cast-Demo"><strong>Download</strong></a> this sample code from <a href="https://github.com/jaysavsani07/Google-Cast-Demo"><strong>github</strong></a> link.</p><p><strong>But Wait!!!</strong></p><p><em>what about </em><strong><em>media controls</em></strong><em>? How to </em><strong><em>pause/stop</em></strong><em> this video, how to add videos in the queue, where’s </em><strong><em>volume controls?</em></strong></p><p>I’ve made another <a href="https://medium.com/@jay.savsani07/google-cast-ios-swift-sender-app-46ee98cadaf7"><strong>article</strong></a> where I’m showing you how to add media controls and add videos in the queue.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24254e6ce507" width="1" height="1" alt=""><hr><p><a href="https://medium.com/macoclock/google-cast-in-ios-swift-sender-app-24254e6ce507">Google Cast in iOS(Swift) Sender App</a> was originally published in <a href="https://medium.com/macoclock">Mac O’Clock</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>