Archives for January 2015

Watch Over Me Version 6.0

To wrap up the First month of 2015, I am going to share the continuous development for the Watch Over Me app.

The last update that I wrote related to my company’s mobile app was back on March 2014. The version was Watch Over Me (WOM) 3.0. It seems to be a long time ago. There has been a lot of changes and we have gone through many new iterations. We have skipped the version 4.0 in order to synch version between the Android and also the iOS app. We have introduced new features in both Version 5.0 and 6.0. In this article, I will make a quick share on my experience on developing the WOM app from Version 3.0 to Version 6.0.

WOM6.0
WOM2.0
WOM2.0


Watch Over Me (WOM) Version 5.0 – 5.1

Before WOM 5.0, I don’t have too much experience and knowledge in Auto Layout. During the time I was developing some cool new features in WOM 5, Apple has announced the new XCode 6 Beta with a new programming language – Swift during the WWDC 2014. In addition to that, Apple actually gave some hints that the future iPhones will have new screen sizes (which turned out to be iPhone 6 and 6 plus).

The new XCode 6 also has a lot of improvements related to the Auto Layout on Storyboard. The improvement is necessary to make sure that the iOS developers can easily optimize for the new iPhone/iPad screen sizes in the future.

I was actually quite excited that Apple has made the AutoLayout so much easy to use. We had our internal discussion in our company and I convinced my boss that we need to spend time in converting the existing non-autolayout supported project to become a fully auto layout supported project. After gaining his permission and I used about 3 weeks of time to complete the AutoLayout conversion (It was not an easy task!).

It turned out that our decision was right. When Apple released the new iPhone 6 and 6 Plus, for me to optimise for the new screen sizes was almost effortlessly. 🙂

WOM6.0
WOM2.0
WOM2.0


Supporting the autolayout on Watch Over Me 5.0 – 5.1 was the major improvement. We also have added a couple more features on the mobile app such as :-

– The Network Contact
The main contact and the emergency contacts are able to know the status event running for each other. Eg: When the main contact is running an event and he/she shares his/her event to the emergency contacts, the emergency contacts are able to see the whereabouts (the map) of the main contact.

– Split Testing on the Sign Up Screen
There are 2 different designs on the Sign Up Screen. Each of the user will only see 1 design. We split test the design to know which design actually will convert the download to become a sign up user. We have been using Mixpanel and also the Google Analytics for the data analytics. This Split Testing was added into the tracking as well.

– Optimisation for iOS 8.0
Without a doubt, optimising the code to support the iOS 8.0 was important as well. There are some new permissions needed in iOS in order to gain the device’s location in the background for iOS 8.

WOM6.0
WOM2.0
WOM2.0


Watch Over Me Version 6.0

The major thing for WOM 6.0 was a total new design on the User Interface. The designer has made the design so much cleaner. I actually love this clean design in WOM 6 way more than any other version of WOM.

We also introduced a new feature calls “The Safety Level“. Safety Level is a feature that encourages the users to make the full use of Watch Over Me app. The user can keep track on his/her progress of using the WOM. Eg: If a user has added 1 contact, then the Safety level is at 20%.

If the user wants to achieve the 100% safety level, the user has to add more contacts, invite the emergency contacts to download the app so that they can watch over each other, add some places (safe zones). With the 100% Safety Level, the user will feel more safe when he/she is using the app.

To encourage users to use Watch Over Me more often, we have simplified the user categories and also removed a lot of restrictions. Eg: Before WOM 6, the Lite user could only launch an event with at most 20 minutes. We have removed this limitation. The only difference between the normal users (Free) and the paid user (Premium) is the SMS. Since SMS notification will cost quite a bit of money, only the Premium users can get unlimited SMS and the free user will get 7 SMS.

There were some further optimisations for iOS 8, iPhone 6 and 6 Plus for this version. On this version, CocoaPods is being used more often now. I have added some of the third party libraries/frameworks on XCode using Cocoapod rather than manually adding them. It is to make sure that any new iOS developer (who wants to continue my project in the future) is able to get the initial configuration on getting the project up and running at the shortest time.

WOM6.0
WOM2.0
WOM2.0


Watch Over Me – Future Version

We will be launching a new feature calls the Safer Streets soon. Moving forward, the Watch Over Me Team will be focusing on the Big Data.

Watch Over Me is a safety app, especially for women. The app will let the users know that which streets are safe based on the statistics from the local government. When a user is nearby a crime prone area, the app will notify the user. The user might want to use Watch Over me when he/she is nearby that area.

There are some challenges to implement the Safer Streets. First of all, the app has to get the user’s location all the time (No matter if the app is active, in the background or in the suspended state). Secondly, when a user is launching the Watch Over Me event, the GPS coordinates of the user has to be sending to the Watch Over Me server every 1 minute.

In order for the Location Manager to support these 2 different functions on the same app, the only way that I can think of is to use 2 different Location Manager instances.

Location Manager #1: Get the Location update even when the app is terminated/killed.
Location Manager #2: Get the GPS coordinates from the user every 1 minute continuously even when the app is in the background.

Here is the demonstration of the WOM 6 with XCode and Simulator

Chan Wu – Audio and Video Freelance iOS App Project

In the last few months, I have been busy with a few iOS freelance projects. Chan Wu – The Audio and Video iOS App Project is just one of them.

Here are the requirements from my client:-
– Have Sign Up and Login.
– Able to Reset and Change Password
– Able to download and play Audio files.
– Able to download and play Video files.
– Support In App Purchase for purchasing the Audio and the Video.

The requirements seem to be quite simple at First. But, I did face some challenges after starting to develop this mobile app. But, I am glad that I am able to solve all the challenges so far.

The Design of the App

A friend of mine has designed the app using Sketch for Mac. I have been using Sketch for more than 1 year and I really love this design tool. Even someone like me, who is not designer, also know how to use the tool. The tool is simple and really easy to use. Here is the screen shot for the simple design:-
ChanWuSketch

Technologies used in this Audio and Video iOS App

For Sign Up and Login API, I am using Parse.com. I have been using Parse for a few mobile applications that I developed. It is very simple to use and it saves a lot of my time – the time that is needed for hosting the server, programming and deploying the server end coding.

Most simple mobile apps do not really need a server. Using the mobile backend as a service provider like Parse.com is already good enough for most simple apps.

The client also does not have to pay extra for hosting a server and also the fee for the extra backend programming work. How cool can that be?

Other than the Sign Up and the Login, I also use Parse API to Reset Password, Change Password and update the In App Purchase content. Parse is able to send an email on your app behalf to the user who forgets his/her password.

For downloading the Audio and Video, I am using the latest AFNetworking 2.5 Framework.

For playing the Audio, I am using AVAudioPlayer. For playing the sample videos on Youtube, I am using XCDYouTubeKit. For playing the videos locally, I am using MPMoviePlayerController.

I am using AutoLayout for this app. In fact, I have been using Autolayout since the release of the XCode 6 beta and I will be using Auto Layout for all the iOS apps that I will develop in the future.

You may check out the auto layout articles that I wrote here:-
1. Basic Auto Layout Tutorial in XCode 6 for iOS 7 and 8
2. Advance Auto Layout Tutorial in XCode 6 for iOS 7 and 8

ChanWu1
ChanWu2
ChanWu3



The screen shots above are taken from both the 3.5 inches and 4 inches iOS devices. The screens are adjusted nicely based on the Auto Layout constraints.

Challenges for this Audio and Video iOS App

One of the First challenges that I encountered was related to downloading the audio/video in the background. If the background task is not keeping active in the background, the downloading process might be suspended by the iOS and the downloaded file will be corrupted.

Luckily, I have done a lot of programming works related to making the background location services active in iOS 7 and 8. With some tweaks of the solution, I actually can make the background downloading of the Audio and Video work perfectly!

Challenge #2: Sometimes when the downloading process could be terminated half way because the user kills the app. So, the file will be corrupted and the user has to download again. To solve this problem, the exact size of each of the audio and video files have to be stored in Parse. Before playing the audio/video, the size of the file has to be checked. If the size does not match, then the file must be corrupted and the user will have to re-download the file again.

Challenge #3: Only one audio is able to play at the same time. I will have to support the function to stop and play the audio file and also change from one audio file to another. There are some small User Interface (touches) like Play Icon and Stop Icon are quite important. They have to be there in order to have the best user experience.

ChanWu4
ChanWu5
ChanWu6



The screen shots above are taken from both the 3.5 inches and 4 inches iOS devices. The screens are adjusted nicely based on the Auto Layout constraints.

Final Words on this Chan Wu – Audio and Video Freelance iOS App Project

I feel happy that I am able to complete this project in less than 3 weeks (part time basis). I learned some new things. This app will be available on the app store soon in both the iOS and Android App store. I will update with the app store links once they are available on the app store.

Getting Location Updates for iOS 7 and 8 when the App is Killed/Terminated/Suspended

This is a long awaited article that I promised to write. A couple months ago, I found a way to get the location update from iOS 7 and 8 even when the app is not active on foreground and not in the background. Yes, you may get the GPS coordinates from the iOS devices even when the app is killed/terminated either by the user or the iOS itself.

Apple does not communicate much with the developers on the ways to do that. If you remember this post from early 2014: Apple’s iOS 7.1 will fix a geolocation bug — after developer sends letter to Tim Cook. In iOS 7.0, Apple prevents the location update when the app is killed/terminated/suspended. But, Apple has fixed the “bug” starting from iOS 7.1 by allowing the app to get the location coordinates.

I have read the release notes for iOS 7.1 but I couldn’t find any information related to location updates and also the way to get the location when the mobile application is terminated/killed/suspended. The iOS 7.0 to iOS 7.1 API Differences for CoreLocation is stated as “No changes“. What?!

But, I didn’t give up in finding the solution. So for a few months, I used my free time to play a bit of the iOS APIs including the CoreLocation APIs. After many months of trials and errors, I finally found the solution.

I will provide the full solution, upload to the Github and write the detailed information on this post.

How to get Location Update for iOS 7 and 8 even When the App is Killed/Terminated

I have written an old article related to getting the continuous Background Location Updates for iOS 7 and iOS 8.

The method to get the location in the background continuously for iOS 7 and 8 is using the method “startUpdatingLocation

and then the next trick would be on the delegate method “didUpdateLocations“. You will have to use a timer and handle the Background Task appropriately. Any missing steps and the location will not be updated continuously.

But in the case of getting the location when the app is terminated/suspended, I can not use [myLocationManager startUpdatingLocation]; The only way to make it work is to use:-

Surprised. Surprised. Yes, I only figured that out after many trials and errors.

Another important trick is, you will have to know how to handle the key “UIApplicationLaunchOptionsLocationKey” on the app delegate “didFinishLaunchingWithOptions“. Here is the sample code:-

In addition to the didFinishLaunchingWithOptions method, I have created a locationManager Instance when the app is active. Here are some code examples:

What exactly is the LaunchOptions Key “UIApplicationLaunchOptionsLocationKey”?

UIApplicationLaunchOptionsLocationKey is very important to get the location update even when the app is neither active nor in the background.

If you read its description from the XCode, it says: “The presence of this key indicates that the app was launched in response to an incoming location event”. What does it mean?

You may realize that when your app is launched for the First time, the App Delegate method “didFinishLaunchingWithOptions” will run once. If you put your app into the background and then launch the app again from the background. This app delegate method will not run again.

The method will only run again after you killed/terminated the app by swiping up from the App Preview Screen and then relaunch from where your app is located.

If your app is a location based mobile application and you need the user’s location even the app is terminated/suspended, then there is another way to launch the app without the user interaction. The iOS will launch the app for you.

When your app delegate methods LaunchOptions contains the key UIApplicationLaunchOptionsLocationKey, it means that your app is launched by the iOS because there is a significant location changes. So, you will have to do something with the new location GPS coordinates return from the location manager.

If order to do so, you will have to create a new instance of location manager and you shall get the location coordinates from the method “didUpdateLocations“.

How Frequent is the Location Updates?

As per Developer Documentation: Core Location Documentation.

Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.

So, you could only expect the location update if the device moves over 500 meters and at most once in every 5 minutes.

From my own testing (I am driving around a lot! To test the Core Locaton API), I only get the location update about every 10 minutes.

Full Source Code for the Location Updates Even when the iOS mobile apps is Suspended/Terminated/Killed

In this source code, I have included the methods to save the location GPS coordinates into a PList file. The purpose of saving into a PList is to record the location coordinates, the iOS Application States and the way locationManager is created (Add From Resume or otherwise).

Here are some simple instructions on how to test this solution:-

1. Download the project from Git Hub.
2. Change to your own Bundle Identifier (If need to)
3. Connect your iPhone with your mac.
4. Launch the app into your iPhone.
5. Killed the app. (Double tap and remove the app from the App Preview)
6. Travel around with your iPhone for a few days.
7. Download iFunBox for Mac or any alternative that allows you to open the app and Read the PList from the “Documents” folder.
8. From the PLIst, you will see something like the screen shot below:-
Getting Location Even When the App is Suspended/Killed/Terminated

When you see the key “UIApplicationLaunchOptionsLocationKey” under “Resume“, it means that the iOS has relaunched the app after the devices has moving significantly from the last known location. If you create a new location Manager instance, you will get new location from delegate method “didUpdateLocations“.

Source Code: GitHub Source Code for Getting Location Updates for iOS 7 and 8 when the App is Killed/Terminated/Suspended