Posts

Showing posts from 2016

Enhanced your programming skill with Assert and Unit Test

Enhanced your programming skill with Assert and Unit Test Sources http://www.pgbovine.net/programming-with-asserts.htm http://stackoverflow.com/questions/1375786/whats-the-point-of-nsassert-actually https://www.youtube.com/watch?v=BbPPnxhcdHo Why you need Assert in your program? 1/ What is Assert? + Assert is the way you make sure a condition in your program must be matched. Otherwise, the app will crash. 2/ What is the point of Assertion? + Using assert will guarantee your program always act like your assumption. => For instance, you write a function with a lot of input and in some situation, inputs mus be valid. Let's say input_1 must comes with input_2. In that case, writing if else and return value is not fit, because you have to handle a lot of return value & error => So that, you will use Assert to make sure your function is used properly. This is very important when you working in a team while writing functions for other people to use. O...

iOS Push Notification with HTTP2

Setup iOS APNS with HTTP/2 Overview: There're one issue while sending iOS notification to multiple devices with old method (send by ftp write stream). Let say you send to 100 devices, ftp write work likes this: 1. connect to APNS Server 2. for each device: send notification by using device_token & payload 3. disconnect In step 2, if there're 1 invalid token (there're many reason make a token invalid: expired, wrong cert, wrong format...etc) the connection will be block without status from APNS Server, if you want to check the status, you have to wait at least 0.5s-1s and using ftp-read to read the status. It's mean you have to check status after every ftp-write and re-connect again if there're an invalid token.  So, to send to 100 devices, you need 50 seconds, that's too long. At WWDC 2015, Apple has introduce a  new notification api by using HTTP/2 This api allow you to send notification as a post request or curl and get the result ...

How to handle iOS Push Notification

Image
Handle iOS Push Notification Handle push notification on iOS is quite hard if you don't understand it. In short topic, I on;y want to present how I handle when user tap on push notification when app is in active/background or killed. First, these are few important notes that you need to keep in mind: - APNS have sandbox & prod certificates, don't forget when you run the app in debug mode, you have to use sandbox. - The registration token cannot be shared, sandbox token cannot be use for prod and vice versa. Others tut: - Apple Documents -  APNS with HTTP2 Generate Push Certificate: cert_file="mobisys_prod_apns.cer" key_file="mobisys_prod_apns.p12" openssl x509 -in $cert_file -inform der -out pem_cert.pem openssl pkcs12 -nocerts -in $key_file -out pem_key.pem cat pem_cert.pem pem_key.pem > PushCert.pem Common Mistakes - using wrong certificate (APNS will return error) / wrong passphrase (in script will retunr error) - using in...