Friday, January 6, 2017

My Love story with Apple Watch

I live in a country where you can not buy Apple Watch and no wonder no one wears one. Few months back when I finally saw Apple Watch, it was only after I has one brought from US. But I knew how it works, what it feels like even before it was released ( I keep very close eye on every Apple Products and leaks ). I carefully observed all the Android Smart Watch to know what Apple Watch would likely be when its finally released. Let alone reading all the Pre-Release video review and tech blogs, I still remember downloading Xcode beta the very day it supported the Watch Development SDK. I was desperate to feel the haptic feedback on my wrist. I really wanted to give the Force Touch on small watch face. Almost every day I used to replay and view keynote announcement with the superb background sound.
Fast forward today and I have mixed feelings with the Apple Watch, but the very problem is with the Smart Watch itself then from superb notification device -Apple Watch. It is NOT fitness device by any stretch of imagination. Actually there has not been a single fitness device in the market as of today ! I find it stupid when they buy products like fitbits and really think its a fitness device. I had same feeling when people used to buy iPod and say its a superb portable MP3 player. When whole world was crazy about iPod, I never had one. My basic problem was with in few years of iPod boom there were already few mobile in the market which could play MP3 songs ( Remember Nokia N-Series ? ). So in some way my future vision of iPod was correct, its was not worth having a iPod when you can easily have mobile which does it all, and today Apple had to kill the iPod because of iPhone. But it took time before Smart Phone were rally capable as iPod replacements, ultimately they did.
I still remember in 1998 when I saw the first Laptop in my life. The first thing I can recalls is that it had a color display ( 256 colors ! ) as I had one desktop in home during 1996 an AT-80286 with single green color display. I can close my eye and recall all the color I could see in that ClipArt which was a Beach Art that came along with Word Perfect in those Dos 5.0 days. My point here is not about mono-chrome or color display. It about Laptop vs Desktop. The size of that Laptop was way bigger then most Desktop these days, let alone all-in-one desktop. It may be portable in some way but over all it had to be alway plugged in and could only be used in desk. It took years of development when laptop were actually portable and worth considered as desktop alternative.
So my whole point is Smart Watch and Fitness device as they call it today are the future devices which are dum and unfit today. Its really stupid to be excited about fitbit which does nothing at all and just track your heart rate and steps you take. The same thing can be archived by any smartphone today and been doing so for years now, some time even better. Apple had a dedicated chip starting from iPhone 5s - M8 just for that called — motion coprocessors, which sole job is to process motion from devices like accelerometer and gyroscope. It is just like GPU which task can be done via CPU as well but they are specialized in doing just single dedicated task of graphics. Which is why we can see dedicated processor today in Apples Air Pods with the wireless W1 chip which has sensors which can even detect whether its on your ear or not ! and many more features to come, which only a dedicated chip can perform.
So if you are unhappy with Apple Watch as it does not have much compiling apps running, or has a poor battery life, you have every right to ditch it and wait for few years when every one will have smart watch in there hand and would be equally in demand like smart watch today. I can predict the future where more people would buy smart watch then smart phone, just like today more people buy smart phone then they buy laptops or desktops. People buys products only if it give value to them. But any technology break thru will take time — in few years from now your smart watch can measure your blood pressure and sugar level. Battery would last weeks not only days. No need to predict about the speed as apple already shipped dual core processor in 2nd generation watch just to speedup app loading.
I am quite happy to say I am one of the contributor to Apples Research oriented open-source framework CareKit on Github. I been working on ResearchKit based app from the very first day Apple released it. I worked on CareKit apps the day they were open sourced it. For last few years I been lucky as well as trying hard to work on apps which are only related to fitness and health. The word “Health and Fitness” might come together more often then not. But the difference is huge. From all I know Apple is trying to make Apple Watch as a Health Care device not fitness ! Unfortunately as of today its technically impossible to make a health related watch / band. So instead Apple is trying hard to make sure it is the best Fitness band hence the Nike+ series on new Apple Watch. No wonder Apple can many tie-ups with health-insurance company which gives watch on discount and insurance discount for people who use Apple Watch. DejaVu ? that what Steve Jobs did with AT&T and iPhone ! 
So I am pretty sure I love my Apple Watch, but will I recommend it to my friend ? It depends — there are two major factor to consider price and battery life. Recent rumor points that Apple Watch Series 3 will have major focus in battery life. But its an Apple product so never expect them to drop the price point below 300$. But I would definitely recommend it to anyone who is about to spend 200+$ on a dum watch or fitbit type fitness band. I still think Smart watch will not be mainstream for next few years dude to those two factor. As we can see people prefer not to recharge there watch like they do with Smartphone and as of now price is expensive.
About price, saying price is very hight would be a wrong analysis. Rather we should say the price does not justify the the value it gives. People will easily pay 1000$ for a watch, if you can show them the value it gives. But as of now the value Apple Watch give is very low. It is a hight quality product with smart apps and smart notifications system but that is it ! There isn't much real value which complies people to spend on it. Like iPhone7+ has a premium price over regular iPhone7 by 120$ but people will easily pay those extra 120$ as they see the value they get from that extra price - bigger display, higher resolution screen, higher RAM, bigger battery and best of all dual camera !
AirPod is priced at 160$ which is selling like hot cake but it has lots of alternative products and yet people are buying it ! Why you may ask, the answer is simple its easy to use, easy to pair, there is no learning curve and give direct value to end users, they know what it is and what it does, how to works and if or not they really need it. In exactly follows Apple Product tag line - "It just works", same isn’t true in case of Apple Watch, many people really don’t know what exactly is a smart watch, it has a learning curve attached to it, the initial version of Watch OS were UX nightmare. But once you use smart watch there is no turning back. You can never go back and wear just a simple watch it feels so empty ! So until Apple gives enough good reason to buy one, people would wait for next brake through to come.

Sunday, January 1, 2017

Getting Started with React Native

Brew Update

$brew update
$brew install node
$brew install watchman
$brew install yarn

$npm install -g react-native-cli

Init Project

$react-native init MyProject
$cd MyProject
$react-native run-ios

This will open up the Simulator but you can always open up Xcode manually
and show some fancy terminal window saying running on part 8081 blaa blaa 



Native means Xcode

$cd ios

$open MyProject.xcodeproj

Run the project and you might see following all over the debugger window !!!

 __nw_connection_get_connected_socket_block_invoke 50 Connection has no connected handler

  1. Xcode menu -> Product -> Edit Scheme...
  2. Environment Variables -> Add -> Name: "OS_ACTIVITY_MODE", Value:"disable"
  3. Run your again


If every thing goes well you can run the project which shows the following screen.


Hello World!

"Welcome to React Native!" ... Seriously ? 
Some thing is very wrong about this window where is "Hello World!"

If you open the project folder you will see the following folder structure - 


You can open the index.ios.js file on any text editor of your choice, but as we are making a native app lets open it in Xcode itself ! 

Drag and drop the file in Currently open Xcode project but make sure you uncheck both 
 - Copy Items if needed  &
-  Add to target


Now open the file and navigate to line sweet 16 ! 
render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
            Hello World!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.ios.js
        </Text>
        <Text style={styles.instructions}>
          Press Cmd+R to reload,{'\n'}
          Cmd+D or shake for dev menu
        </Text>
      </View>
    );
  }

Just replace the Line 20 with Hello World!

Now you do NOT need to hit "Cmd+R" on Xcode, just open the Simulator and hit "Cmd+R"
and with just small flicker for microsecond what you see is new content ! 
WoW !!! Thats the beauty of React Native - No compiling of code just reloading the view.

Note - don’t close the Terminal window; just keep it running in the background. If you do close it by mistake, simply stop and re-run the project via Xcode.

Links - 





Friday, November 11, 2016

Network Router and Request in Swift 3 using Alamofire and SwiftyJSON



Alamofire and SwiftyJSON are the ultimate framework of choice when it comes to Native Swift application development. But there is one small issue we need to manually bridge this two framework manually to get the final output. Hence here is the ultimate guide for how to make Network Request in Swift using Alamofire and get the response as SwiftyJSON using a Router Path.

1. URL Request

We have to first create - enum of a URLRequestConvertible

enum ActivitieRouter: URLRequestConvertible {
case activitiesIndex // Activities Index

case createActivities(param: Parameters) // Create Activities
case updateActivity(activityID: Int, param: Parameters) // Update Activity
case destoryActivity(activityID: Int) // Destroy Activity
}
On each of the request we need to define the http Method 
var method: HTTPMethod {
switch self {
case .activitiesIndex:
return .get
case .activityDate:
return .get
case .getActivity:
return .get
case .createActivities:
return .post
case .updateActivity:
return .put
case .destoryActivity:
return .delete
}
}

each Request can have a sub path like -


var path: String {
let subPath = "activities"
switch self {
case .activitiesIndex:
return subPath
case .updateActivity(let activityID, _):
return subPath + "?" + "\(activityID)"
case .destoryActivity(let activityID):
return subPath + "?" + "\(activityID)"
}
}
Finally the most important for a Protocol is a asURLRequest function which returns the URLRequest

func asURLRequest() throws -> URLRequest {
var urlRequest = NetworkManager.getTokenRequest(path)
urlRequest.httpMethod = method.rawValue
switch self {
case .createActivities(let parameters):
urlRequest = try URLEncoding.default.encode(urlRequest, with: parameters)
case .updateActivity(_, let parameters):
urlRequest = try URLEncoding.default.encode(urlRequest, with: parameters)
default:
break
}
return urlRequest
}

Refer - Gist - https://gist.github.com/bishalg/4d554cd79a138c43c00c17cebf6eb3d3

2. Response Serializable

Now task is to use extend the DataRequest so that we can response back SwiftyJSON object from our network request.





3. Network Request


Finally with our Response Serializer and Network Router ready we can finally make our Network Request. 


static func mostRecent(
onSuccess: ObjectsCallBack? = nil,
onError: ErrorCallback? = nil) {
let route = ActivitieRouter.activityDate(activitiesDate: ActivitiesDate.recentMonth)
let _ = Alamofire.request(route)
.responseSwiftyJSON { request, response, json, error in
guard error == nil else { return }
// create - objects array or object
// return - objects
onSuccess?(objects)
}
}

Thats is it ! Out Networkig code is complete ! 

But you may have noticed that there is one class NetworkManager which is not present ! But that is upto you to manage as per project basic which can be generalized code for say like base url etc.

Links -