Tuesday, 17 April 2018


AWSS3 Transfer Utility Complete Functioning (using Swift iOS)

This demo app requires you to register on AWS and get the Bucket-region, Bucket-name from there to use in your app for further steps.

Features :- 
  1. Single Video/Image upload (With functionality of Pause, Resume, Cancel)
  2. Multiple Videos/Images upload (With each has functionality of Upload, Pause, Resume, Cancel)
  3. See the list of running uploads in-progress.
  4. Mutlipart Video/Image upload.
  5. Get the list of uploaded Videos/Images.
  6. Easily Delete the already uploaded Videos/Images from your bucket

Let's Start With actual codes


1. We require pod file changes such as

pod 'AWSS3'
pod 'AWSMobileClient'


2. Some mandatory changes in info.plist file






3. awsconfiguration.json file that is downloaded from AWS while you created your bucket. Put this file in the same tree directory where your info.plist is present. The below screenshot shows the demo content within it.




4. Some important changes in Appdelegate.swift file.

Here the first method "handleEventsForBackgroundURLSession" will manage  background upload tasks.
Second method will help us to get default AWSServiceManager set up with our Region and PoolId configuration keys.


import AWSS3
import AWSMobileClient

func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {

  AWSS3TransferUtility.interceptApplication(application,         handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
   let credentialsProvider = AWSCognitoCredentialsProvider(regionType:    AWSRegionType.APNorthEast2, identityPoolId: "Your-PoolId-In-String-Format")

   let configuration = AWSServiceConfiguration(region: AWSRegionType.APNorthEast2, credentialsProvider: credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration

   return AWSMobileClient.sharedInstance().interceptApplication(application, didFinishLaunchingWithOptions: launchOptions)
}



5. Create singleton class with any name (I given UploadManager.swift), It will manage all your upload tasks, handling pause/resume/cancel of each task simultaneously, multiple in-Progress uploads, provides list of current running tasks, handling delete of the uploads from your AWS bucket. We will have enum for type of assest to be uploaded and many more.

enum MediaContentType: String {
   case Video = "movie/mov"
   case Image = "image/png"
}



enum UploadStatus: String {
   case Pause = "Pause"
   case Resume = "Resume"
   case Cancelled = "Cancelled"
   case InProgress = "InProgress"
   case Failed = "Failed"
   case Success = "Success"
}

6. The above class will handle all the status of each running task via single instance variable of Transfer Utility

lazyvar transferUtility: AWSS3TransferUtility = {
   return AWSS3TransferUtility.default()
}()

The above transferUtility give update to the UIViewController/collectionViewController/TableViewController via NotificationCenter. 
You just have to create anonymous callbacks for 3 important callbacks which we got from above transferUtility. These are as follows
  • continuationTaskBlock - It will be fired only once when your upload starts and the uploading task gets TransferId from AWSS3 sdk. This TransferId will be used by your controller to distinguish the uploads which are Initiated by that controller. If you want to save instance of that task for further manipluation then you can put in variable like (var uploadTask: AWSS3TransferUtilityUploadTask). In this closure you will fire a ContinuationNotification.
  • progressBlock - It will be fired multiple times while you video/image is getting uploaded. This block will give  you the progess of upload between 0.0 - 1.0 range. 1.0 will denote that your upload completed successfully. In this closure you will fire a ProgressNotification.
  • completionBlock - It will be fired when your upload completes successfully or with error. In this closure you will fire a CompletionNotification.

7. Custom Model will be useful for developer perspective when he want to show/manage multiple uploads in CollectionView/TableView at a time. 



class UploadModel{
  var tranferId: String = ""
  var progress: Double = 0.0
  var status: String = ""
  var failed: Bool = false
  var completed: Bool = false
  var inProgess: Bool = false
  var cancelled: Bool = false
  var paused: Bool = false
  init(){
   }
}

You can keep shared dictionary with upload file URL as key and above model as Value for distinguishing each upload in your whole app.
e.g. var dict: [String: UploadModel] = ["video1.mov": UploadModel(), "video2.mov": UploadModel(), "image1.png": UploadModel()]
As per the dictionary you can update your views or collectionviewcells/ tableviewcells.

On each notification from progressBlock, continuationBlock, completionBlock you can easily update above dict and as per that dict values your view gets updated.

By using this approach you can easily manage many number of uploads at a time.


8. Key Name (Asset name is important) 

For uploading any asset you have to pass key name for that upload and that key name will be assigned to that asset on your AWS cloud bucket. You can keep that key names in array for future purpose such as delete or download from cloud.


9. Delete Asset 

 For deleting the uploaded asset from AWS bucket you have to only give the key name     which you had set when you started a upload for that asset.

For complete source code you can see the gitHub repo



Sunday, 15 April 2018

Star Rating Control With Effortless Dragging Feature Using Swift (iOS)





An Smooth Draggable Star Rating Control

I have seen many apps those who are not having any rating view inside that. Some are having the feature but not so smooth as per the user's perspective. That's why I have created an easy to use pod for draggable rating view with good user experience.

Some fantastic features:

Easy smooth color change dragging can be seen.

- Any color support with the multiple stars. You can give low opacity to high opacity color to each star for looking awesome color change.

- Using this control in Storyboard or within XIB is very easy and developer can   easily see the changes applied to the control such as star selected color and Rate points in the Interface builder.

- Easy to use within any UIViewController or UIView.

- Developer can change the fill color of Star as per his requirement very easily.

- Easy and strong support of IBDesignable and IBInspectable (You can see the changes very easily in Interface builder).

- Easy and strong support of IBDesignable and IBInspectable (You can see the changes very easily in Interface builder).

- The Rate Points can be easily set in Interface builder and as per that the star will be filled.

- The fill color can be easily changed via Inteface builder or at run time.

- Can easily change colors.

- Gives exact Rate points in float(e.g. 1.2, 2.3, 4.9 etc) as per the your drag position.

- Default two buttons are there such as "Rate Now", "Cancel".

- Supports Multiple buttons (requires an array of string to be passed for button names).

- Easy button click delegates are provided via protocols.

Usage Guide:

You want to add pod 'StarRatingDraggable', '~> 1.0' similar to the following to your podfile:

target 'MyApp' do
    pod 'StarRatingDraggable', '~> 1.0'
end

Then run a pod install inside your terminal or from CocoaPods.app.



Without any Images used :) 

Cocoapod url -  https://cocoapods.org/pods/StarRatingDraggable

For source code please visit my GitHub Url

Below are the screenshots and gif is attached for demonstration purpose.
  1. 
    
    
    
    
    
     
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
      
    
    
    
      
    
    
    
    
    
    Thank you so much.