Thursday, February 8, 2018
Why do i see git message like below ? The authenticity of host ' ()' can't be established.
This summary is not available. Please
click here to view the post.
Monday, February 5, 2018
Cloud Functions for Firebase
Cloud functions for firebase allow one to automatically run backend code in response to events triggered by firebase features and HTTPS requests. The code is stored in Google cloud and runs in managed environment.
The cloud functions that a developer write can respond to events generated by below firebase and Google cloud features
1) Cloud Firestore Triggers
2) Realtime database triggers
3) Firebase authentication triggers
4) Google analytics for firebase triggers
5) Crashlytics Triggers
6) Cloud Storage triggers
7) Cloud Pub/Sub triggers
8) HTTP triggers
How does it work?
After a function is deployed, Google servers begin to manage functions immediately. listening for events and running the function when it is triggered. As the load increases or decreases, Google responds by rapidly scaling the number of virtual server instances needed to run your function.
LifeCycle of a function
- The developer writes code for a new function, selecting an event provider (such as Realtime Database), and defining the conditions under which the function should execute.
- The developer deploys the function, and Firebase connects it to the selected event provider.
- When the event provider generates an event that matches the function's conditions, the code is invoked.
- If the function is busy handling many events, Google creates more instances to handle work faster. If the function is idle, instances are cleaned up.
- When the developer updates the function by deploying updated code, all instances for the old version are cleaned up and replaced by new instances.
- When a developer deletes the function, all instances are cleaned up, and the connection between the function and the event provider is removed.
To enable cloud functions, below is what has to be done:
- Setup : Install CLI and initialise cloud functions in firebase project
- Write Functions: Write Javascript code (or Typescript ) to handle events from firebase services, Google cloud services, or other event providers.
- Deploy and monitor : Deploy functions using firebase CLI.
references:
https://firebase.google.com/docs/functions/
HealthKit introduction iOS
To integrate the HealthKit, first step is to enable HealthKit in the app. This can be done via the Capabilities tab
Second main step is to get the permission to access the HealthKit
healthManager.authorizeHealthKit { (authorized, error) -> Void in
if authorized {
// Get and set the user's height.
self.setHeight()
} else {
if error != nil {
print(error)
}
print("Permission denied.")
}
}
We need to request authorisation to share the type of data.
let healthKitStore: HKHealthStore = HKHealthStore()
func authorizeHealthKit(completion: ((success: Bool, error: NSError!) -> Void)!) {
// State the health data type(s) we want to read from HealthKit.
let healthDataToRead = Set(arrayLiteral: HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight)!)
// State the health data type(s) we want to write from HealthKit.
let healthDataToWrite = Set(arrayLiteral: HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)!)
// Just in case OneHourWalker makes its way to an iPad...
if !HKHealthStore.isHealthDataAvailable() {
print("Can't access HealthKit.")
}
// Request authorization to read and/or write the specific data.
healthKitStore.requestAuthorizationToShareTypes(healthDataToWrite, readTypes: healthDataToRead) { (success, error) -> Void in
if( completion != nil ) {
completion(success:success, error:error)
}
}
}
Below is a sample that reads height data from the healthKit
func getHeight(sampleType: HKSampleType , completion: ((HKSample!, NSError!) -> Void)!) {
// Predicate for the height query
let distantPastHeight = NSDate.distantPast() as NSDate
let currentDate = NSDate()
let lastHeightPredicate = HKQuery.predicateForSamplesWithStartDate(distantPastHeight, endDate: currentDate, options: .None)
// Get the single most recent height
let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: false)
// Query HealthKit for the last Height entry.
let heightQuery = HKSampleQuery(sampleType: sampleType, predicate: lastHeightPredicate, limit: 1, sortDescriptors: [sortDescriptor]) { (sampleQuery, results, error ) -> Void in
if let queryError = error {
completion(nil, queryError)
return
}
// Set the first HKQuantitySample in results as the most recent height.
let lastHeight = results!.first
if completion != nil {
completion(lastHeight, nil)
}
}
// Time to execute the query.
self.healthKitStore.executeQuery(heightQuery)
}
Now to write the distance value into the HealthKit store, below is what needed
func saveDistance(distanceRecorded: Double, date: NSDate ) {
// Set the quantity type to the running/walking distance.
let distanceType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)
// Set the unit of measurement to miles.
let distanceQuantity = HKQuantity(unit: HKUnit.mileUnit(), doubleValue: distanceRecorded)
// Set the official Quantity Sample.
let distance = HKQuantitySample(type: distanceType!, quantity: distanceQuantity, startDate: date, endDate: date)
// Save the distance quantity sample to the HealthKit Store.
healthKitStore.saveObject(distance, withCompletion: { (success, error) -> Void in
if( error != nil ) {
print(error)
} else {
print("The distance has been recorded! Better go check!")
}
})
}
references:
Sunday, January 28, 2018
How to Setup Google firebase SDK while using the logic in module?
Just thought to try out firebase messaging SDK to implement a chat feature. The setup is like this
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.google.android.gms:play-services-auth:11.8.0'
compile 'com.google.firebase:firebase-analytics:11.8.0'
compile 'com.google.firebase:firebase-database:11.8.0'
compile 'com.google.firebase:firebase-storage:11.8.0'
compile 'com.google.firebase:firebase-auth:11.8.0'
compile 'com.google.firebase:firebase-config:11.8.0'
compile 'com.google.android.gms:play-services-appinvite:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.android.gms:play-services-ads:11.8.0'
compile 'com.google.firebase:firebase-appindexing:11.8.0'
compile 'com.google.firebase:firebase-crash:11.8.0'
compile 'com.google.firebase:firebase-analytics:11.8.0'
// Firebase UI
compile 'com.firebaseui:firebase-ui-database:3.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Top level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app level build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.examplelib"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':modulemessaging')
}
apply plugin: 'com.google.gms.google-services'
App1(com.example.testapp)
Messaging Module (com.example.messaginglib)
Messaging module has core logic around implementing the chat logic and UI related to the Chat. The intention was to share this across multiple apps if needed.
Below can be done to achieve this:
- Create a Google project in firebase with the package name com.example.testapp (If we try to create a project with package name com.example.messaginglib, this wont work because then it will not be portable to other apps)
- Now download and copy the google-services.json file on to the app1's root folder.
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.google.android.gms:play-services-auth:11.8.0'
compile 'com.google.firebase:firebase-analytics:11.8.0'
compile 'com.google.firebase:firebase-database:11.8.0'
compile 'com.google.firebase:firebase-storage:11.8.0'
compile 'com.google.firebase:firebase-auth:11.8.0'
compile 'com.google.firebase:firebase-config:11.8.0'
compile 'com.google.android.gms:play-services-appinvite:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.android.gms:play-services-ads:11.8.0'
compile 'com.google.firebase:firebase-appindexing:11.8.0'
compile 'com.google.firebase:firebase-crash:11.8.0'
compile 'com.google.firebase:firebase-analytics:11.8.0'
// Firebase UI
compile 'com.firebaseui:firebase-ui-database:3.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Top level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app level build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.examplelib"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':modulemessaging')
}
apply plugin: 'com.google.gms.google-services'
Sunday, December 10, 2017
Monday, June 19, 2017
iOS UIAutomation Brief overview
Provides a way to test the UI in automated way!. This approach relies on the accessibility labels. These tests are run using Automation instrument within Instruments tool. The tests can be run on simulator or on physical device!
Thought to start with this and searching around the Automation framework, it appears that the Xcode 8.x has major changes in this. Now since the UIAutomation framework has come into place, Under Product -> Profile > Automation wont appear anymore.
Now create a new project in Xcode, it will ask whether the test and UITest needs to be included or not. If opt to include, later when run through the Build > Test, it will run the automated UI Tests.
references:
Wednesday, May 31, 2017
How does AMR Bandwidth efficient mode looks like?
In the payload, no specific mode is requested (CMR=15), the speech frame is not damaged at the IP origin (Q=1), and the coding mode is AMR 7.4 kbps (FT=4). The encoded speech bits, d(0) to d(147), are arranged in descending sensitivity order according to [2]. Finally, two padding bits (P) are added to the end as padding to make the payload octet aligned.

references:
https://tools.ietf.org/html/rfc4867

references:
https://tools.ietf.org/html/rfc4867
Subscribe to:
Comments (Atom)