Sunday, November 4, 2018

iOS Swift Image caching and loading libraries

Looking through some of the options below are the ones



PINRemoteImage : PINRemoteImageManager uses the concept of download and processing tasks to ensure that even if multiple calls to download or process an image are made, it only occurs one time

SDWebImage : This library provides an async image downloader with cache support. There are categories for UI elements like UIImageView, UIButton, MKAnnotationView.

Moa: Moa is an image download library written in Swift. It allows to download and show an image in an image view by setting its moa.url property.

Vincent : A small library that makes it easy to download and display remote images.

Kingfisher: Kingfisher is a lightweight, pure-Swift library for downloading and caching images from the web. This project is heavily inspired by the popular SDWebImage. It provides you a chance to use a pure-Swift alternative in your next app.

MapleBacon: MapleBacon is a Swift image download and caching library. It is not currently in active development.


Skeets: Skeets is a networking image library that fetches, caches, and displays images via HTTP in Swift. It is built off SwiftHTTP.

ImageLoaderSwift: ImageLoader is an instrument for asynchronous image loading written in Swift. It is a lightweight and fast image loader for iOS.

YYWebImage:YYWebImage is an asynchronous image loading framework (a component of YYKit). It was created as an improved replacement for SDWebImage, PINRemoteImage and FLAnimatedImage.


reference:
https://medium.com/ios-os-x-development/best-image-download-extension-library-for-swift-3-cf64ec1f84a0

Friday, November 2, 2018

iOS Swift How to openURL

UIApplication.shared.open(URL.init(string: ""), options: [:], completionHandler: nil)

let url = URL(string: "http://www.facebook.com")!
if UIApplication.shared.canOpenURL(url) {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
    //If you want handle the completion block than
    UIApplication.shared.open(url, options: [:], completionHandler: { (success) in
         print("Open url : \(success)")
    })
}

iOS Swift how to convert time to ISO format

Have below extensions

extension Date {
    struct Formatter {
        static let iso8601: DateFormatter = {
            let formatter = DateFormatter()
            formatter.calendar = Calendar(identifier: .iso8601)
            formatter.locale = Locale(identifier: "en_US_POSIX")
            formatter.timeZone = TimeZone(secondsFromGMT: 0)
            formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
            return formatter
        }()
    }
   
    var iso8601: String {
        let formatter = Formatter.iso8601
        formatter.timeZone = TimeZone(abbreviation: "UTC")
        return formatter.string(from: self)
    }
   
    var iso8601IST: String {
        let formatter = Formatter.iso8601
        formatter.timeZone = TimeZone(abbreviation: "IST")
        return formatter.string(from: self)
    }
   
}


extension String {
    var dateFromISO8601: Date? {
        var data = self
        if self.range(of: ".") == nil {
            // Case where the string doesn't contain the optional milliseconds
            data = data.replacingOccurrences(of: "Z", with: ".000000Z")
        }
        return Date.Formatter.iso8601.date(from: data)
    }
}

Firebase : Listening to token update notifications

Below is how to do this.

// Get Instance ID token. Initially this makes a network call, once retrieved
// subsequent calls to getToken will return from cache.
messaging.getToken().then(function(currentToken) {
  if (currentToken) {
    sendTokenToServer(currentToken);
    updateUIForPushEnabled(currentToken);
  } else {
    // Show permission request.
    console.log('No Instance ID token available. Request permission to generate one.');
    // Show permission UI.
    updateUIForPushPermissionRequired();
    setTokenSentToServer(false);
  }
}).catch(function(err) {
  console.log('An error occurred while retrieving token. ', err);
  showToken('Error retrieving Instance ID token. ', err);
  setTokenSentToServer(false);
});

references:
https://firebase.google.com/docs/cloud-messaging/js/client

Wednesday, October 31, 2018

Flutter: Implementing Swipe to Dismiss

Below are the steps to do this:

1. Create List of items
2. Wrap each item in a dismissible widget
3. Provide "Lead Behind" indicators

To create a list of items, its as usual the code is like

Final items = List.generate(20,(i) => "Item ${I+1}")

Now this can be converted into a list like below

ListView.builder(itemCount:10,itemBuilder:(context, index){ return ListTitle(title:Text($itmes[index])})

The crux is that we should have list item wrapped inside a Dismissable object

Dismissable(key:Key(item)),
onDismissed:(direction){
setState(){
items.removeAt(index)
}
Scaffold.of(context).showSnackBar(SnackBar(content:Text(${item dismissed})))
}
Background:Container(color:Colors.red);
Child:ListTitle(title:Text('$item'))

References:
https://flutter.io/cookbook/gestures/dismissible/

Flutter: Navigating to new screen


In flutter world, everything is Widget!

1. Create new screen
2. Navigate to the new screen using Navigator.push
3. Return to the first screen using Navigator.pop.

Thats all mainly to be done.

class FirstScreen extends StatlessWidget {
@Override
Widget build(BuildContext context){
Return Scaffold(appBar:AppBar(title:Text('First Screen')))
}

}


References

Tuesday, October 30, 2018

iOS What is ReplayKit?

Using the ReplayKit framework, users can record video from the screen, and audio from the app and microphone. They can then share their recordings with other users through email, messages, and social media. You can build app extensions for live broadcasting your content to sharing services. ReplayKit is incompatible with AVPlayer content.

References:
https://www.appcoda.com/replaykit/