• Skip to main content
  • Skip to primary sidebar

Ravi Shankar

Tweaking Apps

  • Swift
  • Tech Tips

Add path variable in MacOS for flutter

March 26, 2021 By Ravi Shankar

Flutter commands can be executed from macOS terminal app after adding the path variable to installation of flutter directory on the local machine. You can set Path variable temporarily by executing the following command in the Terminal app or within the Terminal window inside Visual Studio Code

export PATH="$PATH:`pwd`[FLUTTER_INSTALLATION_DIRECTORY]/bin"

where FLUTTER_INSTALLATION_DIRECTORY represents the installtion of flutter SDK on your local macOS

Setting PATH variable permanently

Mac users having Catlina OS and above can follow the below mentioned steps for setting the PATH variable permanently.

  1. Launch Terminal App.
  2. type touch ~/.zshrc and press enter
  3. type vi ~/.zshrc
  4. add export PATH = $PATH[FLUTTER_INSTALLATION_DIRECTORY]/bin
  5. save the changes.
  6. Reload the changes by typing ~/.zshrc

Now you should be able to run all flutter commands using terminal app.

Filed Under: Android, ios Tagged With: flutter, macOS, terminal

How to know the size of the folders in iCloud

February 15, 2021 By Ravi Shankar

If you are using Apple iCloud, the folder sizes are not shown by default when they are not downloaded to your Mac. Doing the following will show all the folder size whether they are downloaded or present only in iCloud.

  1. Using Finder, Access the iCloud drive.
  2. Navigate to folder in iCloud drive. As you can see in the below screenshot the folders size are not shown as they available in Cloud.
  1. Click View menu option and select “Show View Options” from the menu list.
  1. Tick the checbox with the label “Calculate all sizes”

Now the Finder should show all the folder size even if they are present in Cloud only.

Filed Under: Mac Tagged With: iCloud, Mac

Errors were encountered while preparing your device

February 14, 2021 By Ravi Shankar

One of the common error that occurs in Xcode is “Error were encounted while preparing your device for development. Please check the Devices and Simulators Window.” I have noticed this error after Mac OS update or Xcode app update Trying the following

  1. Restart your device,
  2. Close Xcode and try re-running the Xcode project.

Sometimes after restarting the device you might see the following “iPhone is Busy: Making iPhone ready for development”. Give some time for the device after a restart, this might fix the problem.

If you have come across these during any other scenarios, please share them in the comments section. Thank you.

Filed Under: iPhone, Mac, Xcode Tagged With: Mac, Mac OS

We have blocked all requests from this device – Firebase Phone Authentication

September 15, 2020 By Ravi Shankar

Firebase enables apps with Phone Authentication feature but when testing your app you might have received the following error.

We have blocked all requests from this device due to unusual activity. Try again later.

This user usually occurs when you have received too many OTP’s within a short period of time.  And we have to wait for an hour to start using the Phone Authentication feature again.

Recently Firebase has added a feature to add test numbers. This can be found under Firebase Console -> Authentication -> Sign-in method -> Phone

PhoneAuthentication

Now you can use “Phone numbers for testing” section to add test phone numbers. The test numbers will not be blocked and will not affect your testing. I believe you can also use the test numbers for Apple Approval process when publishing your app.

Filed Under: Firebase, ios, Swift Tagged With: Authentication, Firebase

iPhone is not available error message in Xcode

September 8, 2020 By Ravi Shankar

If you are receiving an error “iPhone is not available” when connecting Xcode with iPhone then check iOS version on your iPhone. Make sure it is compatible with the Xcode version.

iPhone is not available

The conflict in versions can be found under the Xcode – Window – Devices and Simulators. In my case the following error was mentioned.

Errors

“The current device configuration is unsupported. This iPhone 7 (Model 1660, 1778, 1779, 1780) is running iOS 13.6.1 (17G80), which is not supported by Xcode 11.7”

The fix was to upgrade iOS on my iPhone to iOS 13.7.

Filed Under: Xcode Tagged With: iphone

Clear CocoaPods cache, re-download and reinstall all pods

September 2, 2020 By Ravi Shankar Leave a Comment

Here is the code snippet to clear CocoaPods cache then re-download and reinstall all pods.

rm -rf “${HOME}/Library/Caches/CocoaPods“

rm -rf “`pwd`/Pods/“

pod update

Source

 

Filed Under: Uncategorized Tagged With: CocoaPods, Swift

PDFKit – View, Annotate PDF file in Swift

April 10, 2020 By Ravi Shankar 1 Comment

In this demo, we will be using PDFKit to View and Annotate PDF file. Let us start by selecting a Single View App template and name the project as PDFDemo.

For this demo, we will be using a PDF file “TheWakingLights.pdf” and this can downloaded from the github project folder. Now drag and drop this file to Xcode project and in “Choose options for adding these files” select “Copy items if needed”

Displaying PDF

In Xcode’s project navigator, select ViewController.swift and add the following lines after viewDidLoad function.

  
            func openPDFDocument() {   
                guard let path = Bundle.main.url(forResource: "TheWakingLights",                        withExtension: "pdf")
                else { 
                 return     
                }      
                let document = PDFDocument(url: path)   
                let pdfView = PDFView(frame: view.frame)     
                pdfView.document = document       
                view.addSubview(pdfView)  

This function does the following

   guard let path = Bundle.main.url(forResource: "TheWakingLights",
                                         withExtension: "pdf") else { return }

Creates URL instance with the path of “TheWalkingLights.pdf” file.

Loads the pdf file in a PDFDocument object

 let document = PDFDocument(url: path)

Creates an instance of PDFView and sets the frame to ViewController’s view then assigns the PDFDocument to PDFView instance.

        let pdfView = PDFView(frame: view.frame)
        pdfView.document = document
        view.addSubview(pdfView)

You will be seeing couple of unresolved identified errors because of missing import PDFKit statement. Add import statement after import UIKit and now you should be able to run the app on the simulator and select text on the PDF

select text

Adding Annotation to PDF

PDFKit provides option to add annotation to PDF file using PDFAnnoation class. Various annotation can be added like Circle, line, Strikeout, Square, Underline, Highlight etc.. Let us see a code example of adding highlight to PDF page.

Add the following code snippet after openPDFDocument function.

  func highlightAnnotation() -> PDFAnnotation {
        let annotation = PDFAnnotation(bounds: CGRect(x: 30, y: 80, width: 230, height: 50),
                                       forType: .highlight, withProperties: nil)
        annotation.color = .yellow
        return annotation
    }

The above code does the following

  1. Creates a PDFAnnotation instance by specifying coordinates for adding the annotation and setting the type of annotation to highlight.
  2.  Then the annotation colour is set to yellow.

In the openDocument function add the following line after view.addSubView(pdfview)

   pdfView.currentPage?.addAnnotation(highlightAnnotation())

This gets the current page from PDFView and sets the highlight annotation. When you run the app on the simulation you will see the highlight as shown below.

final

Download the source code from here

 

Filed Under: ios, Swift Tagged With: Annotation, PDFDocument, PDFKit, Swift

Tab Bar Controller with WebView

April 9, 2020 By Ravi Shankar

In this article, we will see step by step instruction on working of Tab Bar Controller, UIWebView and Activity Indicator by loading couple of web pages using UIWebView in two different Tabs.

Tab Bar Controller

Tab Bar Controller is used for organising list of View Controllers by having seperate tabs for each View Controller. Check out the Apple Documentation for more information.

UIWebView

When you want to allow users to browse website then you can use UIWebView to load those pages. These WebViews needs to be placed inside a container such as UIViewController. Check out Apple Documentation for more information on UIWebView.

Project Setup

Create a new project by selecting Single View Application as project template. You can also choose Tabbed Application but in this demo we will see how to embed a ViewController inside a Tab Bar Controller.

Enter the project details and select the language as Swift.

Embed View Controller inside Tab Bar Controller

Navigate to Main.storyboard in Project Navigator and select View Controller. Now to embed this View Controller inside a Tab bar Controller, click Editor -> Embed In -> Tab Bar Controller

The Interface builder should now display View Controller and Tab Bar Controller as shown below.

Add Second View Controller

Now let us see how to add another tab by setting relationship between second View Controller and Tab Bar Controller. Drag and drop UIViewController from Object library to Interface builder.

Control + Drag from Tab Bar Controller to UIViewController and select view controllers under Relationship Segue. This should add second tab bar item pointing the second View Controller.

Add UIWebView and Activity Indicator View

We are not using Auto Layout or Size Classes for this demo, so disable these features using the option available under File Inspector.

Drag and drop UIWebView from object libary to both the View Controllers. Make sure it is aligned centrally to View Controller and covers the entire View Controller area. Similarly add Activity Indicator View from object libary to top of UIWebView and align to the Centre both vertically and horizontally.

Edit Tab Bar Items

The Tab Bar Controller display two tab bar items which are linked to each View Controller. Add required images for each Tab bar items to the Images.xcassets (Download the images from GitHub project).
To provide a name and image for Tab Bar items, select the item in the corresponding View Controller and enter the details in Attributes Inspector. For the first View Controller, the name and image are set as shown below.

repeat the same for the second View Controller as well.

Link class with UIViewController

The project comes with a default ViewController.swift file which is mapped with the first View Controller. Let us give a proper name to this controller. Unfortnately Xcode Refactor option still does not work for Swift (Xcode version 6.4). Manually rename the file to WorldViewController.swift and also make the corresponding name change in Class.

class WorldController: UIViewController {

Add a second view controller class by right clicking the project, select New File option.

In the choose template screen, select Cocoa Touch Class and provide name as SportsViewController making it a subclass of UIViewController.

Create IBOutelts for UIWebView and Activity Indicator View

Using Assistant Editor, navigate to Main.storyboard in the second window. In the Identity Inspector, set the class name for both ViewControllers to WorldViewController and SportsViewController.

Drag and drop UIWebView from WorldViewController (Interface builder) to WorldViewController.swift to create IBOutlet. Do the same for Activity Indicator View as well.

@IBOutlet weak var webView: UIWebView!

@IBOutlet weak var activityIndicator: UIActivityIndicatorView!

Repeat the same exercise for SportsViewController and create corresponding IBOutlets.

Code Implementation

Navigate to WorldViewController.swift file and add the following code snippet in ViewDidLoad function.

let url = NSURL(string: "http://edition.cnn.com/world")
let urlRequest = NSURLRequest(URL: url!)
webView.loadRequest(urlRequest)

activityIndicator.startAnimating()
activityIndicator.hidesWhenStopped = true

The first three lines of the code create a NSURLRequest and the object is passed to UIWebView loadRequest function. The last two lines starts the Activity Indicator View and sets the property to hide the indicator when it is stopped animating.

We need to tell the Activity Indicator when the page has finished loading. This can be done by implementing UIWebViewDelegate’s webViewDidFinishLoad function.

Add the following piece of code to make the View Controller as a delegate for webView.

class WorldController: UIViewController, UIWebViewDelegate {

and in the viewDidLoad function add webView.delegate = self. This would ensure that the View Contorller can handle any WebView delegate related calls.

Now implement the webViewDidFinishLoad function and stop the animation of Activity Indicator View when the webview has finished loading the page.

//MARK:- WebView Delegate method

    func webViewDidFinishLoad(webView: UIWebView) {
        activityIndicator.stopAnimating()
    }

Repeat the above code implementation for SportsViewController excepy by chaning the URL string.

class SportsViewController: UIViewController, UIWebViewDelegate {
    @IBOutlet var webView: UIWebView!
    @IBOutlet var activityIndicator: UIActivityIndicatorView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let url = NSURL(string: "http://edition.cnn.com/sport")
        let urlRequest = NSURLRequest(URL: url!)
        webView.loadRequest(urlRequest)

        activityIndicator.startAnimating()
        activityIndicator.hidesWhenStopped = true

        webView.delegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //MARK:- UIWebView Delegate methods
    func webViewDidFinishLoad(webView: UIWebView) {
        activityIndicator.stopAnimating()
    }

}

When you finally build and run the project, you should see the follwing on iOS simulator.

Download the source code from here

Filed Under: Apple, ios, Programming, Xcode

  1. Pages:
  2. «
  3. 1
  4. 2
  5. 3
  6. 4
  7. 5
  8. 6
  9. 7
  10. ...
  11. 44
  12. »
« Previous Page
Next Page »

Primary Sidebar

TwitterLinkedin

Recent Posts

  • How to set preferred Wifi network on Mac
  • Attribute Unavailable: Estimated section warning before iOS 11.0
  • How to recover Firefox password from Time Machine backup
  • Show hidden files and folders on Mac
  • How to request a refund for apps in App Store

Pages

  • About
  • Privacy Policy
  • Terms and Conditions

Copyright 2022 © rshankar.com

Terms and Conditions - Privacy Policy