Reputation: 21
I have an iOS application that uses Parse; this app. connects two users at the same time, so they are able to share some images with each other. A generic user can take a picture and this pic. is automatically uploaded on Parse and downloaded from the other user.
In order for each user to display the latest image the other one uploaded, they are both polling Parse every 0.2 sec using a NSTimer object. Everything seems to work fine, apart the fact that sometimes the app exceeds the maximum amount of 30 req/sec provided by a free Parse account.
The Parse guide states that actions like login, saving and finding content from Parse, count as an API request; I only have two users logging in at the same time and since I am polling Parse each 0.2 sec for each user, in one second I have 10 requests processed by both users.
On Parse I tried to use the "Events" tool on the Analytics section but from the "API requests" diagram I couldn't figure out where the problem was, so I used another tool called "Explorer" to perform a query that loads all the API requests made by my application in a precise time frame.
From the outcome of the query I have noticed that Parse is performing other background requests, that will probably affect the number of maximum requests available for my account.
Is my implementation of the uploading/downloading process (polling Parse each 0.2 sec), the best way to achieve my goal or there is a more efficient way to do it, maybe using Parse Notifications?.
I am aware that I can increase the max. amount of req/sec simply upgrading my Parse account, but since I haven't completely understood how this API requests calculation works, I'd like to know if someone can point me in the right direction with some examples or explanations.
Upvotes: 0
Views: 91
Reputation: 57114
No. It is not the best way at all. For the exact reason you mentioned: you create faaaaar to many requests and too much traffic.
The better approach would be to use silent push notifications
.
You need to write some cloud code that gets triggered when one user uploads a picture or trigger it from the uploading to the receiving user directly. The receiving device reacts to the silently received notification and loads the image and informs its actual user.
Upvotes: 1