Google Analytics on iOS dispatchPeriod - how does it work? - ios

I can't find any specific documentation about the dispatchPeriod variable in the Google Analytics SDK for iOS.
If I set it to 10 does that mean it will send data to the Google Analytics server every 10 seconds? Does it only send data if new page views or events have been recorded or is it going to send data regardless? I don't want to use this feature if it will eat up too much battery life but my app has very few events to record (basically just launching and exiting). If I set the dispatch time to 10 seconds and only record events when the app opens and when it closes will it be continually dispatching during my apps runtime or will it only dispatch when those events are recorded?

I have just added Google Analytics to my app and here is what I found out:
If you don't explicitly call dispatch and have set the dispatchPeriod to let's say 10 secs, then when you call trackPageview/Event/Whatever, these requests to Google Analytics are being queued and actually sent in those 10 secs periods. If there are no requests in the queue, your app doesn't send anything (to be precise I didn't sniff the network communication, but at least the GANTrackerDelegate methods are not called).
Confirmed, just sniffed communication with Wireshark and there is no traffic between my iDevices and the world when I don't track anything.

Related

how to call a web service daily on particular time using local notification in objective c

My requirement is, I need to call a Web-Service and the count of the data should come on the local notification content on daily at 8 AM
example : you have 10 new notification, the 10 is the count of the data in an array.
Some one please help me to do this.
Thanks in advance.
you cant schedule something like this offline but you have 2 options that differ
with thr app background refresh API you may come close. If you opt in to that api, ios will wakeup your app when it has spare cycles and will give you cpu time to run some code and allow you to do this.
the background refresh api was meant for 'periodic' updates like this IMO. What you cannot do with it though, is schedule any EXACT times/dates/intervals you want to be woken. You can recommend times to ios but it may or may not stick to the plan (this depends on device use .... battery .... time of day...... etc)
another option are a backend that sends 'silent' push notifications at your required time. IOS would wake your app for those notifications and as they are silent, the user wont see it.
you can have a backend send you non silent pushes. Your app will be launched on tapping the notification and you can do whatever you like
==> option 1 works offline, option 2 and 3 require connectivity and even worse a decdicated backend to support it. IMHO option 1 is often very good and underrated.

Background network request from app

As a slightly open question: Can/how does one send a network request every 5 minutes from a minimised iOS app?
In our case, we want to make sure that a certain message written when offline is sent as soon as the user regains internet access, even if the app is minimised.
Attempts at a solution
Most people are thinking down the 'app posting it' line, which hits the 3 min limit as mentioned.
Is there anything around the server pinging the app (perhaps with a notification) to trigger the app to respond with the required information?

iOS 7+ Is it possible for an application to send data via network while app is inactive?

iOS 7+, 8 (last one not released yet, however targeting on it).
The app.
As a user I start the app and switch to other apps (mail, safari, etc.), leaving the app running but not a foreground one.
The app establishes HTTP connection to server via Internet and starts periodically sending GPS location data to the server (with some interval).
Is it possible while the app is not on the foreground? I mean is it possible to get geolocation data and periodically send it from the app to the server via HTTP POST while using other apps?
If the answer is "YES", please help me with references. I will investigate it further.
Yes, and the method you want to research is performFetchWithCompletionHandler:
Implement this method if your app supports the fetch background mode.
When an opportunity arises to download data, the system calls this
method to give your app a chance to download any data it needs. Your
implementation of this method should download the data, prepare that
data for use, and call the block in the completionHandler parameter.
When this method is called, your app has up to 30 seconds of
wall-clock time to perform the download operation and call the
specified completion handler block. In practice, your app should call
the completion handler block as soon as possible after downloading the
needed data. If you do not call the completion handler in time, your
app is terminated. More importantly, the system uses the elapsed time
to calculate power usage and data costs for your app’s background
downloads. If your app takes a long time to call the completion
handler, it may be given fewer future opportunities to fetch data in
the future. For more information about supporting background fetch
operations, see “App States and Multitasking” in iOS App Programming
Guide.
https://developer.apple.com/library/ios/documentation/uikit/reference/uiapplicationdelegate_protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:performFetchWithCompletionHandler:
Just as Mike mentioned, you should look into background fetch. For more details, checkout this objc.io post.
The information you need should be in the Background Fetch section.

Google Analytics iOS SDK, very long dispatch interval

I've integrated Google Analytics iOS SDK in my iOS App, I want to set a long dispatch interval to avoid frequent network calls. I want to set 6 hours or longer interval.
// set Google Analytics dispatch interval, eg: 20 seconds
[GAI sharedInstance].dispatchInterval = 6*60*60; // dispatch after every 6 hours
I have few queries:
Q1. What will happen if App is killed just before the data is dispatched, will data be sent immediately when app is launched next time? (eg: app killed just few minutes before the dispatch interval).
Q2. Let's suppose app tries to dispatch data after 6 hours but network is not available at that time. will data be dispatched again after next 6 hours as aggregate of 12 hours data?
Any suggestion for optimised approach? I don't want to consume network bandwidth after every few seconds or minutes just for minor data.
dispatchInterval default is 120 (2 min).
Did you send a lot of datas? If you have vital datas, I suggest to keep it as 120(or better). As it use very minimal bandwidth.
If you are offline, the data will be sent when you are online again. (use event to test it easily in your app)
According to Google.:
Data collected using the Google Analytics SDK for iOS is stored locally before being dispatched on a separate thread to Google Analytics.
If a user loses network access or quits your app while there are still hits waiting to be dispatched, those hits are persisted in local storage. They will be dispatched the next time your app is running and dispatch is called.
More info here: https://developers.google.com/analytics/devguides/collection/ios/v3/dispatch

HTTP Request as background task with local notifications in iOS

If you aren't that into Android, there's something called a "background-service" for the applications in that OS. Which basically gives the developer a opportunity to make some background tasks without forcing the application to be in foreground.
So are there something like this in iOS? (Version 5 and newer) What I basically want to do is to call a API and fetch some JSON data every minute, then parse the result and then present a local notification banner to the user depending on the result that were fetched from the HTTP request. I hardly believe that this shouldn't be possible in iOS, but I haven't found anything like this yet.
Call the API once every minute and fetch some JSON data.
Parse the JSON data into and add some logic to handle the data.
If a local notification should be presented or not, depends on the result from the request.
This can only be done in a very limited manner. Pure background processes are only allowed in special forms (for example media players, VOIP or location based services). You can start limited background tasks with beginBackgroundTaskWithExpirationHandler:, but they won't run forever.
More information can be found here: Run app for more than 10 minutes in background

Resources