Mobile App Development in Lucknow


cropped-android-apps-111.jpg

Hey,

Lucknow is being hub of software technology and mobile application development. Day by day increasing list of software companies in Lucknow, is showing that there is a lot of opportunity to grow. We are listing some mobile development companies operating in Lucknow.

1. STPL

Website: https://www.stpl.biz/

2. Laikor infosolution pvt ltd

Website: https://www.laitkor.com/

3. Unicode System

Website: http://www.unicodesystems.in/

4.  NewGenApp

Website: http://www.newgenapps.com/

5. AlcanzarSoftware

Website: http://www.alcanzarsoft.com/

6. 18Pixel

Website: https://www.18pixels.com/

7.Medma Infomatix

Website: http://www.medma.in/

8.Erectorlab

Website: http://erectorslab.com/

9.Erectorlab

Website: http://erectorslab.com/

Advertisements

Common method in Swift


1. Check for any field empty in NSDictionary

class func checkforEmptyValueinDictioanty(dic:NSDictionary)-> Bool{

for (keyVal, dataVal) in dic {

  if (dataVal.length()==0){

                println(\(keyVal): \(dataVal.length()))

                return false

            }

            

        }

        return true

    }

2.Email validation

class func isValidEmail(testStr:String) -> Bool {

let fullNameArr = testStr.componentsSeparatedByString(“@”)

        var firstPart: String = fullNameArr[0]

        if let range = firstPart.rangeOfCharacterFromSet(NSCharacterSet.letterCharacterSet()){

 }else{

            return false

        }

      let emailRegEx = “[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}”

 var emailTest = NSPredicate(format:“SELF MATCHES %@”, emailRegEx)

        let result = emailTest.evaluateWithObject(testStr)

        return result

    }

3. Alert in Swift

class func commonAlert(title:String,msg:String,curView:UIViewController){

        var device : UIDevice = UIDevice.currentDevice();

        var systemVersion = device.systemVersion;

        var iosVerion : Float = (systemVersion as NSString).floatValue

        if(iosVerion >= 8.0) {

    

        var alert = UIAlertController(title: title, message: msg, preferredStyle: UIAlertControllerStyle.Alert)

            alert.addAction(UIAlertAction(title: “Ok”, style: UIAlertActionStyle.Default, handler: nil))

                  // return alert

            curView.presentViewController(alert, animated: true, completion: nil)

        }else{

            let alert=UIAlertView(title: title, message: msg, delegate: self, cancelButtonTitle: “ok”)

            alert.show()

           

        }

    }

4. NSUserDefaults in swift as common function

class func saveToUserDefault(value:AnyObject, key:String)

    {

        NSUserDefaults.standardUserDefaults().setObject(value, forKey:key)

        NSUserDefaults.standardUserDefaults().synchronize()

    }

    

    class func userDefaultForKey(key:String) -> String

    {

        return NSUserDefaults.standardUserDefaults().objectForKey(key) as NSString

        

    }

    class func userDefaultForAny(key:String) -> AnyObject

    {

        return NSUserDefaults.standardUserDefaults().objectForKey(key) as AnyObject!

    }

    

    class func userdefaultForArray(key:String) -> Array<AnyObject>

    {

        return NSUserDefaults.standardUserDefaults().objectForKey(key) as Array

    }

    

    class func removeFromUserDefaultForKey(key:String)

    {

        NSUserDefaults.standardUserDefaults().removeObjectForKey(key)

        NSUserDefaults.standardUserDefaults().synchronize()

        

    }

5.Get screen height and width

let _screenWidth=UIScreen.mainScreen().bounds.size.width

let _screenHeight=UIScreen.mainScreen().bounds.size.height

Use different font text in a Label in swift


let secondLabel=UILabel(frame: CGRectMake(0, 16, _screenWidth2, 20))

        secondLabel.textColor=UIColor.whiteColor()

        secondLabel.textAlignment=NSTextAlignment.Center

        secondLabel.font=UIFont(name: “Arial”, size: 12)

        bottomView.addSubview(secondLabel)

        

        let attrSting=NSMutableAttributedString(string: “I agree to the Terms of Service and Privacy Policy.”)

        

        NSLog(“text length is %d”, attrSting.length)

        

        attrSting.addAttribute(NSFontAttributeName, value: UIFont(name: “Helvetica-bold”, size: 14), range: NSMakeRange(15, 16))

        

        attrSting.addAttribute(NSFontAttributeName, value: UIFont(name: “Helvetica”, size: 12), range: NSMakeRange(31,4 ))

        

        attrSting.addAttribute(NSFontAttributeName, value: UIFont(name: “Helvetica-bold”, size: 14), range: NSMakeRange(35, 15))

        

        secondLabel.attributedText=attrSting

Use HexColor in Swift as a color


Add it in your class 

extension UIColor {

   convenience init(red: Int, green: Int, blue: Int) {

       assert(red >= 0 && red <= 255, “Invalid red component”)

       assert(green >= 0 && green <= 255, “Invalid green component”)

       assert(blue >= 0 && blue <= 255, “Invalid blue component”)

       self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)

   }

   convenience init(netHex:Int) {

       self.init(red:(netHex >> 16) & 0xff, green:(netHex >> 8) & 0xff, blue:netHex & 0xff)

   }

}

Use it where you need…….

var color = UIColor(red: 0xFF, blue: 0xFF, green: 0xFF)

var color2 = UIColor(netHex:0xFFFFFF)

Open Setting from your iOS application


Step 1.  Add a method in AppDelegate

private func setSettings() {

        let userDefaults = NSUserDefaults.standardUserDefaults()

        let defaults = [ “AppTitle” : “SettingLinker” ]

        userDefaults.registerDefaults(defaults)

        userDefaults.synchronize()

        println(userDefaults.dictionaryRepresentation())

    }

Step 2. Call this function from didFinishLaunchingWithOptions

    setSettings()

Step 3. Add a setting bundle

            Application —> New file —> Resources —> Setting Bundle

******** it will be a pre defined bundle . Change title according to your requirement.

Step 4. Add a Notification to trace changes of setting in Your ViewController’s ViewDidLoad method

override func viewDidLoad() {

        super.viewDidLoad()

        

        NSNotificationCenter.defaultCenter().addObserver(self,   selector: “traceChanges, name: NSUserDefaultsDidChangeNotification, object: nil)

        setupView()

        // Do any additional setup after loading the view, typically from a nib.

    }

Step 5. Add a method named  traceChanges .

func defaultsChanged() {

        setupView()

    }

Step 6. Add a new Method name  setupView

private func setupView() {

        let userDefaults = NSUserDefaults.standardUserDefaults()

        yourLabelL.text = userDefaults.stringForKey(“AppTitle”)

    }

Step 7. Add a button and addEvent Listener

@IBAction func gotoSetting(sender: AnyObject) {

        UIApplication.sharedApplication().openURL(NSURL.URLWithString(UIApplicationOpenSettingsURLString))

    }

Best Of luck..

enjoy coding

A soft touch of Apple HealthKit :: HealthKit Tutorial


Screen Shot 2014-10-14 at 6.54.20 PM

HealthKit :: The HealthKit framework provides a structure that apps can use to share health and fitness data. HealthKit is designed to manage data from a wide range of sources, automatically merging the data from all the different sources based on users’ preferences. Apps can also access the raw data for each source and let the app perform its own merging.

Some Key feature related to HealthKit is following

  • To use Healthkit in your application , First you have to enable it . To  enable HeakthKit you have to perform following step .

         Project setting—>Capability pane —> make enable Healthkit

         This requires that you sign in to your Apple developer account, and   

          then acquires the  appropriate entitlements for your app.

  • The HealthKit data is not saved to iCloud or synced across multiple devices. The data is only kept locally on the user’s device. For security, the HealthKit store is encrypted when the device is not unlocked.
  • HealthKit can be used only in iPhone and iPod  , Not in iPad. Developer can check for HealthKit availability using  isHealthDataAvailable().it return a Boolean value that indicates whether HealthKit is available on this device.
  • HKHealthStore is used to managed all types of data in HealthKit.
         if let massNumber = numberString("50") {

      let weightType =   HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass)

            let weightValue = HKQuantity(unit: HKUnit(fromString: "kg"), doubleValue: massNumber)

            let metadata = [ HKMetadataKeyWasUserEntered : true ]

            let now = NSDate()

            let sample=HKQuantitySample(type: weightType, quantity: weightValue, startDate: now, endDate: now, metadata: metadata)
  • All access to the data is performed through a HKHealthStore object, and it is this that you request permissions from. access request of data from Store is done as following
private func requestAuthorisationForHealthStore() {

  let dataTypesToWrite = [

    HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass)

  ]

  let dataTypesToRead = [

    HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass),

    HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight),

    HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMassIndex),

    HKCharacteristicType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierDateOfBirth)

  ]

  self.healthStore?.requestAuthorizationToShareTypes(NSSet(array: dataTypesToWrite),

    readTypes: NSSet(array: dataTypesToRead), completion: {

    (success, error) in

      if success {

        println("User completed authorisation request.")

      } else {

        println("The user cancelled the authorisation request. \(error)")

      }

    })

}
  • Samples are saved in store using HKHealthStore object . sample code for this is following

          

        func saveSampleToHealthStore(sample: HKObject) {

  println(“Saving weight”)

  self.healthStore?.saveObject(sample, withCompletion: {

    (success, error) in

    if success {

      println(“Weight saved successfully “)

    } else {

      println(“Error: \(error))

    }

    })

}

  • Data from Store can be retrieved from HKQuery . sample code to retrieve is following

            

          func perfromQueryForWeightSamples() {

  let endDate = NSDate()

  let startDate = NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitMonth,

    value: –2, toDate: endDate, options: nil)

  let weightSampleType = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass)

  let predicate = HKQuery.predicateForSamplesWithStartDate(startDate,

    endDate: endDate, options: .None)

  let query = HKSampleQuery(sampleType: weightSampleType, predicate: predicate,

    limit: 0, sortDescriptors: nil, resultsHandler: {

    (query, results, error) in

      if !results {

        println(“There was an error running the query: \(error))

      }

      var data=results as [HKQuantitySample]

    })

  self.healthStore?.executeQuery(query)

}

HealthKit Support 50 type of exercise including

     • Archery

  • Yoga
  • Swimming
  • StairClimbing
  • SnowSports
  • SkatingSports
  • Hocket
  • Fishing
  • Dance
  • CrossTraining

Type of values that can be stored in store is following

  •          1. Body Mass
  •          2. Height
  •          3.Step Count
  •          4.Blood glucose
  •          5.Blood alcohol content
  •          6.Dietary energy consumed
  •          7.Body Temperature
  •          8.Inhaler usage

         these are known as HKTypeIdentifiers.

For detail check on https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HealthKit_Framework/index.html#//apple_ref/doc/uid/TP40014707

Continue reading