Archives for 2014

Auto Layout Advanced Techniques for iOS 8 and 7 using XCode 6 on Storyboard

As promised from a previous post (How to Use Auto Layout in XCode 6 for iOS 7 and 8 Development) that I will write another article related to more advanced techniques in AutoLayout to develop iOS mobile apps for iOS 7 and iOS 8.

In this article, I am going to share a few common layouts, scenarios and problems that I am facing when I am developing the iOS app using the Auto Layout. I am going to show the techniques to link different objects together using constraints inside the same view controller.

Auto Layout for iOS 8 versus iOS 7

I believe most iOS developers will still include iOS 7 under their development plan. So before getting started, it is good to know the differences between Autolayout in iOS 7 compare with iOS 8.

One of new things in iOS 8 is the Layout Margin. Layout Margin is a new property available in UIView for iOS 8. So, any objects inherit from UIView will have this property. If you are developing the app for both iOS 7 and iOS 8, you should not use Layout Margin (or use layout margin in a smart way).

So, if you have any constraints related to layout margin and you didn’t do a proper check before launching the app on iOS 7 devices, the app might crash or the arrangement of the objects might be out of order.

Whenever you are trying to add new constraints from the storyboard in XCode 6, “Constrain to Margins” is ticked by default as show as the screen shot below. The meaning of this selection is to add constraints with the new property in iOS 8.

Constrain to Margins iOS 8

If the deployment target of your app is iOS 7 and above and any of your constraints have this layout margin, the XCode will complain with the warning “Layout attributes relative to the layout margin on iOS prior to 8.0”.

Layout attributes relative to the layout margin on iOS prior to 8.0 warning

If you are developing the app for both iOS 7 and 8, it is best to “Untick” the Constrain to Margins.

How to use Auto Layout with more than One Object

Using the autolayout constraints with more than one object inside the same view controller can be tricky.

You may ask yourself some questions when you are deciding the design before trying to link the objects together inside the view controller:-
1. How many objects are inside the view controller?
2. Is the object fixed in height or have flexible height?
3. Is the object fixed in width or have flexible width?
4. How would the object be positioned inside the view controller. (Eg: Stick on the top of the view controller)
5. What is the relationship between Object A and object B? (eg: The Object B is positioned on the Right of the Object A)

Example:-
Let’s say I have a view controller with 2 Text Fields (Email and Password) and one Login Button.

Here is my decision:-
1. Both the Text Fields have fixed height (50 px) but with flexible width.
2. There will be a Navigation Controller on the top of the View Controller.

Decision on EmailTextField
– The Top of the First Text Field (EmailTextField) will stick to the Top Layout Guide of the Navigation Controller
– The Left of the EmailTextField will stick to the Left Side of the Superview (Leading Space)
– The Right of the EmailTextField will stick to the Right Side of the Superview (Trailing Space)

So, there are 4 constraints that I will have to associate with this EmailTextField object. The below screen shot shows the 4 constraints:-

Auto Layout with more than One Object1

If you do it correctly, You will see 4 constraints on the Size Inspector and also the Document Outline like the screen shot below.

Auto Layout with more than One Object2

Next, I want to add the PasswordTextField onto the screen. I will position it on the bottom of the EmailTextField.

Decision on PasswordTextField
– The Top of the First Text Field (EmailTextField) will stick to the Bottom of the EmailTextField.
– The Left of the PasswordTextField will stick to the Left Side of the Superview.
– The Right of the PasswordTextField will stick to the Right Side of the Superview.

Here is screen shot for adding the constraints for the PasswordTextField.
Auto Layout with more than One Object3

If you do it correctly, you will see that the Top Space of the PasswordTextField is Linked to the Bottom Space of the EmailTextField like the screen shot below:-
Auto Layout with more than One Object4

IMPORTANT TIP: Double Click on the constraint on the Size Inspector to view the detailed relationship of the constraint.

Finally, let’s link the constraints for the last object – the login button.

Decision on the Login Button
– The button has fixed height: 60 px
– It will stick on the bottom of the view controller with constant: 20 px (distance)
– There will be constant 16 px on the Left and Right of the superview
Auto Layout with more than One Object5

The above auto layout guide for multiple objects inside the same view controller is very straight forward because the top objects (EmailTextField,PasswordTextField) does not have any relationship with the bottom object (Login Button).

The autolayout will become more complicated when you want to add a UIScrollView and links all the objects together.

How to use UIScrollView with Auto Layout

Using the Auto Layout with UIScrollView can be tricky. I personally having a tough time with ScrollView when I first started learning Auto Layout. After some trials and errors for a few weeks, I almost got it right.

The most basic rule of using ScrollView with Auto Layout is you will have to set up the constraints from the top of the ScrollView to the bottom of the Scrollview and from the left to the Right. You can not have any missing link neither the horizontal nor the vertical layout. Or else the XCode will complaint!

Let’s just use the same example as the above and we will add all the 3 objects inside the UIScrollView.

First of all, we will have to add the scrollview onto the empty View Controller inside the Storyboard. For my personal preference, I would stick the top of the ScrollView on the top layout guide and not under the UINavigationBar. Remember, the Scrollview will always have flexible height and flexible width.

Autolayout with Scrollview1

If you do it correctly, you will see that the leading and the trailing space to the super view will be 0, the bottom space to the bottom layout guide is 0 and also the top space to the top layout guide would be 0 as well like screen shot below:-
Autolayout with Scrollview2

Next, putting the 2 text fields and also the login button inside the scrollview. If I connect the constraints exactly like the first example that I showed above. The XCode will complaint. The reason is adding a scrollview will change the behaviour of the Autolayout.

The common complaints:

1. Frame for “XXX” will be different during run time.
To Solve it: Add another constraint to align the object to the center of the superview (ScrollView)

Autolayout with Scrollview3

Autolayout with Scrollview4

2. The Views are vertically ambiguous or (Scroll View has Ambiguous scrollable content height)
To solve it: Link the objects from the top to the Bottom of the Scrollview (No missing relationship in the middle)

For the above case, I will make another constraint (Horizontal Center in Contrainer) to centrelize the EmailTextField. And then “Control Drag” to link up PasswordTextField with LoginButton with a vertical space.

Autolayout with Scrollview5

The XCode will love you by adding the 2 extra constraints and stop complaining.

How to Resolve Conflict Constraints and Other Autolayout Errors/Warning

Here are some of the common AutoLayout Errors/Warnings:-

Warning #1: Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0

Description: This only happens when your app has to support iOS 7 and the app have UILabel on one of your View Controller Objects inside the storyboard. And you didn’t tick “Explicit” on the “Preferred Width”.

How to Resolve this issue?
A. If you know where to locate the specific UILabel, just select the UILabel Object on the Storyboard. Then, Make sure that “Explicit” is ticked. If you do not want to have a fixed width, just assign the value as 0 (zero). The width for the UILabel will be based on the other connected constraints for this UILabel.
Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0

B. When your storyboard has many view controllers objects and also many UILabel, you may find it hard to locate the specific UILabel object. So, you will have to use the following steps in order to location the UILabel.

Resolve the Automatic Preferred Max Layout Width Warning From SourceCode

1. Right Click the Storyboard and “Open As” -> “Source Code”

2. Use the keyboard Key (Command + F) or Click “Find” -> “Find” on the Navigation bar of the XCode to launch the Search Window. Paste the code

into the Find Window.
3. Click the Search Icon then Select “Edit Find Options”.

4. Then, Choose “Regular Expression”.

5. The Find Window will show you all the UILabel does not have preferred Layout Width. You will have to paste

into all the UILabel like below screen shot until the count for the Find Window is 0.

6. Lastly, you will have to Open the Storyboard again. This time choose “Interface Builder – Storyboard”.

The above steps will solve all the Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0 warnings.

Warning #2: Frame for “xxx” will be different at run time.
Description: This warning is letting you know that the frame for the object inside the storyboard does not match with the constraints that you connected on that object.

How to Resolve this issue?
Most of the time, this issue can be solved easily by going to the “Resolve Auto Layout Issue” tab and choose either “Update Frames” or “Update Constraints”.
Update Constraints

Sometimes, you may face a situation where the view controller has multiple Auto Layout Warnings. You may have already spend some time to fix the issue but the issue is too complicated that you might not be able to fix easily.

From my own experience in a situation like this, it is better to clear all the constraints for all the views inside the view controller. And then reconnect the constraints all over again for all the views. The chance is that after you reconnecting the constraints, you would not see the issue again.
Clear Constraints for all the views

More Auto Layout examples for iOS 7 and 8

On going…. Need some time to complete the tutorial under this section

How to Use Auto Layout in XCode 6 for iOS 7 and 8 Development

The Auto Layout is available on the Storyboard for iOS or OS X development since XCode 5. But, I didn’t adopt the Auto Layout technology for the projects that I developed because there are only 2 different iPhone screen sizes (3.5 inches and 4 inches). During that time, adjusting some views to position them inside 2 different screen sizes using codes seem to be easier than learning how to use the Autolayout Constraints inside the storyboard.

I believe all the iOS developers will have to use Auto Layout for future iOS apps development projects because there are rumours that Apple will release iPhone 6 with 2 new screen sizes (4.7 inches and 5.5 inches). Although Apple has yet to confirm on the validity of the rumours, from my research on various resources/websites, I can confirm that the rumours have very high chances to be the accurate.

Even from the new XCode 6 Beta itself, Apple has released 2 new iOS simulators (Resizable iPhone and Resizable iPad) for the iOS Developer to work with. There is also a new Storyboard preview function for different iPhone screen sizes at the same time.

Update on September 2014: The rumour is true and Apple will release iPhone 6 (4.7 inches screen) and iPhone 6+ (5.5 inches) soon. The latest XCode 6 Golden Master contains iPhone 6 and iPhone 6 Plus simulator as well.

Resizable iPhone Simulators
Screen shot above shows the Resizable iPhone and iPad Simulator.

XCode 6 Beta Preview Function
Screen shot above shows the XCode 6 Beta Storyboard Preview Function with different iPhone screen sizes at the same time (Only 3.5 and 4 inches iPhone screen preview available for now).

Potential iPhone 6 Screen Sizes and Resolutions

Before iPhone 6, there are 2 standard screen resolution sizes that most iOS app developers use as a guidelines when developing iOS mobile app. These 2 screen sizes are 320 x 480 (3.5 inches) and 320 x 568 (4 inches). Here are a list of iPhone screen Resolutions (including iPhone 6):-

iPhone 4S
Screen Size: 3.5 Inches
Resolution: 640 x 960 (Half: 320 x 480)

iPhone 5
Screen Size: 4.0 Inches
Resolution: 640 × 1136 (Half: 320 x 568)

iPhone 5S/5C
Screen Size: 4.0 Inches
Resolution: 640 x 1136 (Half: 320 x 568)

iPhone 6
Screen Size: 4.7 Inches
Resolution: 828 x 1472 (Half: 414 x 736)
Resolution: 750 x 1334 (Half: 375 x 667)

iPhone 6 Plus
Screen Size: 5.5 Inches
Resolution: 906 x 1704 (Half: 453 x 852)
Resolution: 1242 x 2208 (1/3: 414 x 736)
The size of iPhone 6 Plus is @3x scaling. So, it is divided by 3.

So, other than 320 x 480 and 320 x 568, we have to use 375 x 667 and 414 x 736 at the Resizable iPhone Simulator.

After you build and run your project with the Resizable iPhone Simulator, you may set Width as 414, Compact and Height as 736, Regular and remember to click “Apply” like screen shot below:-

Resizable iPhone Simulator in Xcode 6

Update on September 2014: It is best to use the iPhone 6 and iPhone 6 Plus simulator provided on the XCode 6 Golden Master (GM) to test and run, rather than using resizable iPhone simulator because the resizable simulator is quite unstable as of now.

How about iPhone 4? I believe iPhone 4 will be dropped from the support for iOS 8. So, it is not worth to mention here.

The Basic 15 Auto Layout Position Guides on XCode 6

When I tried to use auto layout with many different objects within a view controller, I always messed up the entire view controller. Almost every single time, the connected constraints for the objects are not correct which caused the objects to position in awkward positions.

Out of frustration on one fine day, I decided to come out with the most basic positions that one single object can be positioned inside a view controller. Using these basic guides/rules, I will slowly connect the constraints with other objects inside the same view controller.

First of all, you will have to determine the Size of the Object inside the View Controller.

An object can have 4 different sizes:-
– The Object has fixed Height and fixed Width
– The Object has fixed Width but with flexible Height
– The Object has fixed Height but with flexible Width
– The Object has flexible Height and flexible Width

But we may ignore flexible Height and flexible Width for most objects because the only potential objects using the flexible Width and flexible Height could be UIScrollView and UIView. We can safely assume that most objects have only 3 potential sizes.

The object can be located in 5 different positions:-
– Always at the Center of the SuperView
– Always stick to the Top Layout Guide
– Always stick to the Bottom Layout Guide
– Always stick to the Left side of the SuperView
– Always stick to the Right side of the SuperView

So by doing the math, we will have an object with 3 potential sizes in 5 potential positions. So, we will have a total of 3 x 5 = 15 different potential auto layout guides for one single object in a single view.

I have developed a simple XCode Project to shows all these 15 different auto layout guides for my personal reference. I have also uploaded this project to Github and hope that other iOS developers who are learning Auto Layout will find it useful.

The Basic 15 Auto Layout Position Guides on XCode 6

You may download this simple project from the Github to see how I set the different constraints for all these 15 different scenarios: 15 Auto layout Scenarios for iOS 7 and 8 Development

How to Use Auto Layout in XCode 6 for iOS 7 and 8 Development

It is still possible to use codes to adjust the views based on different screen sizes. But, when there are too many different iPhone screen sizes, adopting the autolayout technology will actually ease our development work by having us to code less.

Height and Width on XCode 6 Storyboard

When you start to develop the iOS app from XCode 6 using the storyboard, the First thing that you find would be a new strange square 600 x 600 layout. It is quite different compare with the previous version of XCode which the storyboard only offers the tall and the short layout (for 3.5 vs 4.0 inches screen).

When you click at the bottom of the Storyboard screen, you will see a pop up view indicating Any Width | Any Height as the base value for the layouts. You can select any of the value (eg: Compact Width | Any Height) and the layout of the storyboard will change based on what you choose.

Here are some important steps to Use Auto Layout in XCode 6 for iOS 7 and 8 Development:-

Step 1: Make sure that you understand The Basic 15 Auto Layout Position Guides above.

Step 2: Always start to develop the app from Any Width | Any Height.
– Any constraints that are added on Any Width | Any Height layout will be auto converted to other screen layouts.

Step 3: Try to satisfy all the constraints in Any Width | Any Height layout, adjust the constraints on other layouts Only when necessary.
– Most of the constraints relationship should be constructed on Any Width | Any Height layout. You will have to use the Storyboard preview and also the different sizes of iPhone simulators to see if the constraints position all the Objects correctly or otherwise.
– If you find out that the position is not correct for a certain screen sizes (eg: incorrect position for screen above 4 inches), then only you try to adjust the constraints for other layouts like (Compact Width | Any Height or Compact Width | Regular Height)

Step 4: Learn to group different elements together to have the best result.
– Sometimes you will have to group different UI objects together inside a view in order for them to sit next to each other. Without Grouping, the objects might not be positioned at the right place. An example scenario would be: 2 Buttons sit next to each other at a constant width. These 2 buttons will be position at the bottom center of the screen.

Here are the steps to group the objects inside a view:-
1. Select all the elements that you want to group
2. Go to Editor -> Embed In – > View
3. Then you may centralise the newly created superview of the objects on the center of the view controller.

Group the objects inside a view on Xcode Storyboard
Screen shot above shows the way to group 2 different buttons using a view on Storyboard in XCode.

I hope this simple post can help some iOS developers to learn the basic of Auto Layout. There are still many different strategies/techniques to use constraints in the view controller such as using Priority to avoid the constraint conflict. You could have potentially seen some warnings/errors such as “ScrollView has ambiguous scrollable content height” when using Autolayout.

I will share more advance auto layout techniques for iOS 7 and 8, the potential warnings/errors and the way to solve them in another blog post. Meanwhile, you may download and check this simple project from the Github to see how I set the different constraints for all these 15 different scenarios.

Github Project: 15 Auto layout Scenarios for iOS 7 and 8 Development

Update on 10 Oct 2014: I have written an Autolayout Tutorial with more advance techniques/tips here: Auto Layout Advanced Techniques for iOS 8 and 7 using XCode 6 on Storyboard

The Comparison Between Swift and Objective-C Programming Language

Swift programming language has been announced and released on XCode 6 Beta for over 2 months. Although it is not out of the Beta version yet, we (the iOS mobile Developers) could get our hands dirty on the playing with the Swift code to understand the differences between the Swift and Objective-C Programming Language.

Let’s us make some comparisons between Swift and Objective-C and understand the differences between these 2 programming languages. We can also identify the strengths of Swift over Objective-C.

Swift Programming Language and Its Development

Swift Programming Language is been developed by Chris Lattner and his team since year 2010. He is the director of the Apple Developer Tools such as Xcode, the Instruments and the compiler. As of year 2014, it has been in the development for 5 years.

Steve Jobs passed away on late 2011. The development of Swift has started more than 1 year before Steve Jobs’s passing. It means that Steve Jobs could have involved in part of the Swift Language Development. There is a chance that it is Steve Jobs’s vision that a new and powerful programming language is needed to replace Objective-C (a 30 years old programming language). Only the internal development team could verify if this is a fact or just a random guess.

From watching the WWDC videos on Swift, we understand that Swift is designed to be more
Safe
Modern
Power

The syntax for Swift is designed so that the programmer/developer could make less erroneous codes. When there is any problematic code, the error/warning inside the text editor of the XCode will be much clearer that forces the programmer to correct the mistake. When we program using Swift, we will also write lesser lines of codes when comparing with Objective-C. For example, there is no need of semicolon “;” at the end of each line of code. A few powerful features such as Extensions have been introduced on Swift to ease the developer to create great apps in less time.

The Differences of Swift and Objective-C Code Syntax

Let’s compare the differences between Swift and Objective-C Programming Language. Let’s learn what makes Swift a better programming language.

I have used NSDictionary, NSMutableDictionary, NSArray and NSMutableArray quite extensively on most of my iOS project. So, let’s start to compare these syntax.

Dictionary and Array in Objective-C versis Swift

Objective-C Code

Swift Code

From the above Objective-C and Swift codes are doing exactly the same thing for Dictionary and Array declaration and initialisation. With just the First glance, I believe that you will realize that the code for Swift is simpler and also short.

Check Out the complete documentation for Swift Programming Language: Swift Programming Documentation by Apple.

Swift, Home Automation and Indoor Positioning System

There is not much update on this website on June and July because I have been busy with my company project (Watch Over Me 3.0 Enhancement) and also my personal project. The personal project is a dating social network on mobile. This personal project is developed with the intention to test my skills and to learn new things. I do not have any plan to monetize it at the moment. To develop this app, I am using Facebook and Parse API heavily. The “engine” behind this app is mostly complete. I still have to add some features and polish the interface before ready to be uploaded to the appstore. There will be more updates on this dating social network within the next 2 months.

The Apple Worldwide Developers Conference 2014 (WWDC 2014)

There are some exciting announcements by Apple during the WWDC 2014. For example, the new programming language – Swift and the new frameworks like Home Automation and also the new APIs on CoreBluetooth and CoreLocation. All of these will be ready to ship by Apple probably on September 2014 together with the stable version of XCode 6 and iOS 8.

Swift – Programming Language

Swift is a new programming language that is developed by Apple for iOS and OSX. When the Swift was announced, I did a simple Google search and I was surprised to find out that Swift has been in the development for almost 5 years. It means that Steve Jobs could have been involved in the early stage of the development of Swift. He could have been the visionary behind the development and he knows that Swift could replace Objective-C in the future and make the apps development much easier, faster and powerful.

Since the release of Swift on the XCode 6 Beta, there has been many discussions on the comparison between Swift and Objective-C. At the First glance, I found out that the variable declaration is somewhat similar to JavaScript. After watching the WWDC videos, I understand that Swift is designed to be more safe, more modern and more power.

Safe: The design of the syntax + the auto error detection by the XCode has made the chances of a programmer to create an erroneous code will be reduced to the minimal.
Modern: The programming syntax is modern. It was described as the “Objective-C without the C”. Develop a similar app using both Objective-C and Swift, the development using Swift could be faster because the developer can develop using lesses lines of codes. Some unnecessary syntax such as @ and { } has been removed when comparing with the codes in Objective-C.
Power: Swift has some powerful features such as Nested type and Extensions that will help developer to create great apps.

Here is a list of videos titles related to Swift on WWDC 2014:-
402 Introduction to Swift
403 Intermediate Swift
404 Advanced Swift
406 Integrating Swift with Objective-C
407 Swift interoperability in depth
408 Swift playgrounds
409 Introduction to lldb and the Swift repl
410 Advanced Swift Debugging in lldb

You should be able to watch/download it from: https://developer.apple.com/videos/wwdc/2014/

I have watched all these videos and started to learn Swift since a month ago. I am going to get more serious in it on August and hope that I can master it together with some new features on XCode 6. I am going to convert all the codes on the dating app that I developed to Swift as well.

Apple mentioned that they have big plans for Swift. Well, we shall wait and see.

Home Automation and Indoor Positioning System

Apple has released a new framework calls HomeKit for the iOS developers. The HomeKit can be used to create mobile apps to communicate and control different devices in a house such as television, lightings, air conditioner, garage door and more.

The core technology in the HomeKit is Bluetooth LE. So, the communication using the iPhone/iPad to control the home devices will not consume a lot of battery. Since iBeacon (the indoor proximity system by Apple) is using Bluetooth as well, so, HomeKit and Indoor positioning system are closely related and may compliment each other.

Bluetooth technology is going to play an important role for the years to come as I believe the development of the technology is moving towards indoor. There are many exciting developments in the Smart Home and also Indoor positioning technology. Just to name a few:
1. Google has acquired Nest (maker of “smart” thermostats and smoke alarms for homes) for USD $ 3.2 Billions.
2. The new CoreLocation framework by Apple for iOS 8 will support multistory building. It means that you will know which floor that you are currently standing inside a building from your iPhone.

I am not sure about you. But, I am very excited on the latest development on the mobile app ecosystem. I really can’t wait to see how these new technologies shape the world in the next few years.

iOS Region Monitoring and Location Manager

One interesting feature in the new version of Watch Over Me app is Crime Zone. The main purpose of the crime zones is to notify the user of Watch Over me when he/she is passing the area. Watch Over Me app will ask if the user wants to be watched over during that time.

We have accumulated some trustable and reliable resources from various websites from the Internet to gather the crime zone areas in 7 major cities in 5 different countries (Malaysia, USA, UK, Australia, Thailand). These 7 cities are our test regions and we will be adding more regions in the future.

iOS Region Monitoring and Location Manager

I am using Region Monitoring from the Location Manager to implement this feature on the iOS Watch Over Me app. This particular module is not hard compare with getting the location in iOS 7 in background mode.

The maximum regions that an iOS device can monitor is only limited to 20. So, I have to come out with a good strategy to only get and monitor the regions that are useful to the users.

This is the logic we use for the region monitoring in iOS:-
1. Getting the current location from the user.
2. Send the current location to the server.
3. The server will return all the regions within a 20 km radius from the current location
4. If there are more than 20 regions, the server will only send the closest 20 regions from the current location.
5. After receiving the regions, the app will start to monitor the regions.

A Potential Bug for locationManager delegate method didEnterRegion

After the app has been released on the app store, we are still constantly in testing on the region monitoring on Kuala Lumpur (KL). We have 8 monitored regions in KL at the time of typing this article.

On one fine day, my colleague saw a bug with multiple region notifications triggered at the same time. The location of my colleague is at least 3000 meters away from the nearest region that we monitored. I have double checked on the radius and also the coordinate for all the regions that we monitor in KL, there wasn’t any discrepancy of the data.

Region Monitoring Bug
iOS Region Monitoring Bug
Region MonitoringiOS Region Monitoring


The screen on the Left shows the bug when 4 notifications triggered at the same time when the device is NOT even close to any of the regions.

The screen on the Right is a simple app that I made to stimulate the location of the device (Green Marker) and also the location (Red Marker) and the radius of each region (Red Circle). The Blue Circle is the estimation of the radius of the device when it triggered the notification for all 4 regions. The estimated radius for the device is about 4700 meters! It should not happen.

I have searched through various websites (StackOverFlow, Apple Developer Forum and etc.), I couldn’t find other developer faced the same issue like mine. I saw a lot of questions on NOT getting any notification when passing through a region, but my case is the entire opposite.

I am not sure if this is the fault on my code, on iOS system level or the problem on the local Telco in my country. I have posted a question on StackOverFlow for more than 1 week but I didn’t get any answer as well.

How to Fix this Bug?

Without much reliable information, I can only do trial and error in order to fix this bug. I have been trying a few different method on trying to fix the bug. This includes setting the distanceFilter = 10 for the locationManager. Previously, it was kCLDistanceFilterNone because I want the app to detect every single movement.

My colleague still saw this bug after a few days of testing. So, the above solution is no good.

After experimenting for sometimes, I found a solution that works good.

1. Whenever a user enters a monitored region, he/she will get a notification in the locationManager delegate method didEnterRegion. But due to the bug, this method is not reliable. I have to use a smart way to filter out the fake location.
2. I found a way to get the recent location of the user from locationManager.
3. After the app gets the user location, the app will make sure that the location is within the region before deciding to send the location notification to the device.

From my research, this location is not 100% reliable, especially if there isn’t any location based running at the background. But generally, it is good enough to filter out the bad location which may trigger multiple notifications for different regions.

Here are the example code:

iBeacon and Indoor Positioning System (IPS)

I have been excited for the Indoor Positioning System (IPS) Technology for a quite while. In fact, one of the main reasons I train myself to be an iOS developer is because I want to develop some excited Location and Positioning Based Mobile apps that will change the way we do things in life.

What is Indoor Positioning System?

Indoor Positioning System is a new technology that probably only exists in less than 15 years ago. When I am trying to find more information about this IPS technology from Wikipedia, the earliest research paper on the reference was dated based in year 2009. But when I am searching through google search, I found some research papers on early 2000s.

So, this is a relatively new technology that we haven’t see much applications on the real world yet. But, this will definitely change in the next 5 years.

With the exponential growth of the smart phone users, we have seen a lot of location based (GPS) mobile applications that pop up in the last 5 years. For your information, Global Positioning System (GPS) was developed in 1940s during the World War 2. So, GPS was initially developed to pinpoint the enemy’s location so that they can launch a missile to that location. Thanks to the mobile technology, the GPS technology has been highly commercialised to the mass market in the last 5 years.

All the smart phones users know very well that the Global Positioning System (GPS) does not work well inside a building. This is where the Indoor Positioning System comes into existence.

I am actually betting that the Indoor Positioning System will become highly commercialised within the next 5 years. There will be a lot of innovative mobile apps coming out of it that will make our life easier.

What is iBeacon?

Beacon is actually a device that transmits signal to its surrounding to determine the approximate distance betweens some objects and the broadcaster. We have seen some real world applications like on a car with reverse sensor. That sensor is actually a type of beacon.

iBeacon, on the other way, is a term trademarked by Apple. It is a new iOS technology which is only available on iOS 7 and onwards. iBeacon is using Bluetooth LE (Low Energy) to determine the your location as far as 10 50 meters inside a building.

The vivid location based Mobile apps users know very well that the location based apps usually consume a lot of battery, especially on the navigation mobile apps.

One of the big advantages over the GPS technology is that the IPS technology such as Bluetooth consumes a lot less battery. Even if you turn your bluetooth on 24 hours per day, you almost never feel any battery drain at all.

Some people mentioned that iBeacon is better than the Near Field Communication (NFC) technology that is available on some Android devices. It is due to its greater distance in discovery (iBeacon: 10 50 meters vs. NFC: 20 cms) and energy efficiency.

You may learn the details on the iBeacon here: iBeacon – Wikipedia.

So, What’s Next?

Some people mentioned that after Steve jobs passed aways, there isn’t much innovations coming out from Apple. This isn’t true. We have seen the innovation from Apple from iPhone 5s which has the fingerprint recognition technology and also this iBeacon Technology.

The DNA that Steve Jobs has implemented into Apple will last for a very long time. Apple was late in the map and location technology when comparing with Google. But, it has been catching up fast.

Apple has acquired an Indoor Positioning company – WiFiSlam for $20 millions. There isn’t much news from Apple after the acquisition. I believe we will hear something within the next 1 year.

Don Dodge, who is a Developer Advocate for Google, mentioned in his blog post that there will be many potential markets that could adopt IPS technology. There will be a lot of winners in this technology. He is also an investor and also advisor for some of the IPS startups.

I am very excited to see what will be coming out from iBeacon and Indoor Positioning System within the next 5 years. I just started to learn iBeacon iOS framework and I will make a new post when I am ready to share.