You have integrated Plot into your iOS app and you want to make sure you have done it right? Then continue to read this post.
Update January 8th 2014: We have updated this post after the release of version 1.5.0 of our iOS plugin.
Of course the most important feature of Plot is sending location based notifications. To ensure that Plot is integrated properly you can test that functionality by verifying you can receive a location based notification. The easiest way of doing that is adding a test notification at your location. When you have received that notification, you can be sure that notifications can be received. It is advisable to create a separate account for testing purposes. Creating an extra account just for testing purposes is free and it will ensure that your users don’t accidentally receive a test notification.
Let’s start with creating a notification to test. You can create a notification in our dashboard. Login with the private key we have provided you. First create a place at your current position. Then add a notification and set the status of that notification to ‘published’.
Plot tries to update its database every few hours. This isn’t influenced by whether the app has been opened or closed in this period. It is designed this way to increase the energy efficiency of Plot. Therefore when a new notification has been added it may take up to a few hours before that notification is downloaded and may be received by the user.
When you start an iOS app with Plot integrated for the first time, it will update the local list of notifications, so your newly added notification can be sent out immediately. For best results enable WIFI on your phone.
If you create a test notification and don’t want to wait a few hours before the notification will be sent, simply re-install the app and open it. The local list of notifications will be updated and, providing your are at the right location, your notification will be sent immediately.
To aid you in debugging, Plot will provide diagnostic messages in the console. These messages are only enabled when Plot is compiled with a debug configuration. The messages show which notifications were considered for showing and how far Plot thinks you are from these notifications. This makes it clearer why a notification has been or hasn’t been shown.
For example the output could be:
2013-11-15 16:34:51.460 PlotExample Plot| Plot enabled 2013-11-15 16:34:54.349 PlotExample Plot| Loaded new notifications (1 total) 2013-11-15 16:34:54.349 PlotExample Plot| Notification: a9f242b4be384923896168dc2c134585 - Wiki Notificati... 2013-11-15 16:34:54.383 PlotExample Plot| Distance to a9f242b4be384923896168dc2c134585 - Wiki Notificati...: 4018 (range: 200)
The first line shows that Plot is enabled. The second line shows that Plot has loaded the notifications. The third line shows which notification is loaded. On the last line is shown that the distance to that notification is 4018 meter, which is much further away than the range of 200 meters. Therefore that notification isn’t shown.
Because Plot keeps receiving the location of your device in the background you must ensure that your application stops doing work in the background. Tasks you need to look out for are timers that are scheduled repeatedly and subscriptions on location services.
Before starting a task ensure that your application is in the foreground. NOTE: when your app starts it may stay in the background. Don’t assume it will directly move to the foreground. Checking that your app is in the foreground, or your app is starting and will move to the foreground can be done with: application.applicationState != UIApplicationStateBackground. IOS provides notifications that can be used to detect whether the app moves to the background, so you can pause the tasks when the app transitions to the background. There is another notification that informs when the application moves back to the foreground.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive) name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
When your app makes use of MKMapView in a view that is directly loaded when your app starts and has the option “Shows User Location” enabled, then your app will start using GPS when it starts. Also when it starts in the background. You should enable that option programmatically after the view did appear instead of directly when the view loads.
XCode comes with a tool called Instruments that shows multiple metrics related to power usage. Instruments can be found in the XCode menu behind “Open Developer Tool”. The tool you need here is “Energy Diagnostics”.
It shows among other things how much of the CPU it utilizes and whether GPS is enabled. Keeping GPS enabled in the background really reduces battery life.
An important use case to test is what happens when your application starts in the background. The easiest way to trigger this is to start your app, allow location services and then restart your iPhone. Your app will then start with Plot in the background.
We have shown you how you can verify that your app can successfully receive notifications and how you can verify that your app doesn’t consume too much energy when in the background.
We hope that this blogpost made it clearer how to properly integrate Plot. If you have problems during one of these steps, we have a discussion group you can post your question to. We will then help you as best we can.