How to get the bandwidth of internet connection in IOS [duplicate] - ios

This question already has an answer here:
iOS Detecting connection speed or type [duplicate]
(1 answer)
Closed 9 years ago.
Using Objective C, I need find the specific bandwidth of the network an iOS is connected to. Does anyone have any hints for finding this information with code?

You just need to place a file big enough in one of your servers (or somewhere else)
This could be done using a normal NSURLConnection.
Before start downloading, set up a timer. When your file's been downloaded, you stop the timer. Then you have the amount of time it took for the device to download X MB. You can do the calculations based on this. Once this has been done, the file can be discarded.
Of course, this will vary depending on how far the device is from the server, ping, routing, etc... but I think it's good enough for an implementation this simple. If you want more accuracy repeat the operation several times and calculate average speed.

Related

Matching time on iPhones worldwide - synchronizing playing video?

Two Quick questions:
Are the seconds value of the clock/time on all iPhones around the world the same? If not, are they close at least & how close?
Do the seconds value of the clock/time on all iPhones around the world change/increment at the exact same time?
Upon request, I'm editing this post and adding the purpose for asking such questions:
I'm trying to make a corporate app that can play a video on multiple iPhones around the world at the exact same time (or as close as possible, ideally the exact same moment). Could you please guide me on how to do this?
Much thanks in advance!
To answer your actual question per se,
Are the seconds value of the clock/time on all iPhones around the world the same?
The fact is, yes, 99.9999% of iPhone users simply use the "get time from a server" system which is of course built in to any phone now.
(Indeed, this simply applies to any Windows, Mac, Android, iOS, etc etc device.)
Yes, they are all "about the same".
You could rely on it being within a second or two, probably even closer.
You cannot rely on it being closer than that.
It seems that you
I'm trying to make a corporate app that can play a video on multiple iPhones around the world at the exact same time
Synchronization in general and streaming video (is it streaming?) is a well-explored (and rather technical) branch of software engineering. (For example a massive amount of game engineering, which is a huge field, relates to inside-the-frame synchronization.)
This is not something you can learn how to do in five minutes, and it requires a stack of device-cloud stuff. Go ahead and ask new questions about this, or just google to get started! Good luck.
Regarding using push notifications.
With the push notification you would send a time. You would not send a "command to play it".
So say right now it is (example) 09:13:28. You would pick a time in the future by a couple minutes. So let's say 09:14:30.
Then using a push notification you would send that information "09:14:30" (and a video file name) to everyone connected. (You'd be sending a "command" as it were, to play video X at 09:14:30.)
Then every device would in fact play the video at 09:14:30 (simply using the local clock, as asked in your question).
Be aware that sending push notifications is extremely sloppy and slow. It can take any amount of time from 5 seconds to a minute, AND quite often there are delays beyond that (ie ten minutes or the like).
I personally would not even bother starting to experiment with push notifications, for the project you describe.
These days, making apps is entirely about using device-cloud services, such as Firebase. Everything is about "OCC" - occasionally connected computing.
(So, you can't get a job "making apps" anymore - i.e. if you know how to move buttons around on an iPhone screen. You get a job because you can make a total, live, device-cloud system - indeed such as you are making.)
Indeed your example project is the perfect such "demo" project for learning about how to do modern apps.
Simply use Firebase to sync everything up.
You'll essentially put a piece of information on Firebase ("play video X at 09:14:30") and that information will be communicated fairly quickly/reliably to everyone connected.
For the particular task you describe, I personally would use PubNub which is faster than Firebase and basically made for game-like problems precisely like you describe.
http://pubnub.com
If you truly needed performance/reliability better than pubnub, you are really talking major engineering. So, the (buildings of) engineers who make live games at Nintendo, Warcraft etc, would tackle such an issue as "being even faster than PubNub".
So, the answer in brief!
The very short answer then to your question posed is:
Learn to use the various device-cloud services, which are at the heart of all apps today. (Knowing how to make "an Android or iOS app", as such, is of no consequence today.) For your particular problem, you'll want to use PubNub specifically, as it is built for precisely realtime problems such as this. (Firebase more leans towards "OCC" type data problems.)
Really that's it.

Does Anyone Really Know The Time? (ha!) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Can an iOS app access the time of events using the iOS clock?
This would seem to be a simple question… but couldn’t find anything on Google search or here on Stackoverflow either.
Q1. I’m doing a feasibility study on building an app that needs to record the precise moment an event occurs. For example, if an event in astronomy, nature (e.g. lightning) occurs at 16h18m22s (4:18pm, 22 seconds), and the app supports the user to record when the event occurs, can the exact time the user taps the button be recorded using the iOS clock as a time reference?
Q2. How much precision is offered by the iOS clock? Is it possible to record the event-time as a decimal of one second? Milliseconds?
For example: 16h18m22s50c (where the last two digits represent 50 centiseconds or 0.5 of a second).
Q3. Would it be safe to assume that, apart from timezone differences, that everyone’s iOS device is reading exactly the same time, what one might call "universal device time"?
Q4. Or if this approach using the iOS clock seems a bit clunky, especially where ultra accuracy is required, would it be smarter to get a feed from an atomic clock server?
Thanks for any input on this one. Appreciated!
Cheers
Q1: yes! Using [[NSDate date] timeIntervalSince1970] you get sub-millisecond precision
Q2: you are going to get milliseconds as explained in Q1.
Q3: Since timeIntervalSince1970 gives you exactly what it says (the time interval since 1970), yes - that is a property unaffected of timezones. (watch out for the but below)
Q4: using a server will destroy any way of retrieving an accurate result since you have to contact the server and wait for a response, that will take around 100ms which is far worse than every inaccuracy the device clock would have.
BUT
the user can change its device time which makes the measurement still exact but useless since it no longer reflect the actual time! What you can do in this case is
retrieve the current timestamp of the action on the device
contact a server with a properly set up clock
compare the measurement and ignore the measurement if it is too far off / alert the user to correct his system time. A comparison threshold of half a second should be okay unless your server is very far away or very slow.

Establishing synchronized music streaming across devices

I am attempting to stream audio files from a server to iOS devices and play them completely synchronized. For example on my phone I might be 20 secs into a song and then my friend next to me should also be 20 secs into the song as well. I know this is not an easy problem to solve, but I am attempting to do so.
I can currently get them within one second of each other by calculating the difference in time between the devices and then have them sync up, however that is not good enough because the human ear can detect a major difference in a second and this is over WIFI.
My next approach is going to be to unicast the one file from the server and then have the all devices pick it up directly from the server and then implement some type of buffer system similar to netflix so that network connectivity would be a limiting factor. http://www.wowza.com/ is what I would use to help with that.
I know this can be done, because http://lysn.in/ is does it with their app and I want to be able to do something similar.
Any other recommendations after I try my unicast option?
Would implementing firebase help solve a lot of the heavy lifting problems?
(1) In answer to ONE of your questions (the final one):
Firebase is not "realtime" in "that sense" -- PubNub is probably (almost certainly) the fastest "realtime" messaging for and between apps/browser/etc.
But they don't mean real-time in the sense of real-time, say, as race game engineers mean it or indeed in your use-case.
So firebase is not relevant to you here and won't help.
(2) Regarding your second general question: "how to synchronise time on two or more devices, given that we have communications delays."
Now, this is a really well-travelled problem in computer science.
It would be pointless outlining it here, because it is fully explained here http://www.ntp.org/ntpfaq/NTP-s-algo.htm if you click on "How is time synchronised"?
So in fact, to get a good time base on both machines, you should use that! Have both machines really accurately set a time to NTP using the existing (perfected for decades) NTP synchronisation.
(So for example https://stackoverflow.com/a/6744978/294884 )
In fact are you doing this?
It's possible that doing that will solve all your problems; then just agree to start at a certain exact time.
Hope it helps!
I would recommend against using the data movement to synchronize the playback. This should be straightforward to do with a buffer and a periodic "sync" signal that is sent at a period of < 1/2 the buffer size. Worst case this should generate a small blip on devices that get ahead or behind relative to the sync signal.

My Application's main method does not work after pulling battery from Blackberry device [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
How to setup alternate entry point in Blackberry application?
I have made a blackberry application which need to run automatically after phone reboot (by pulling battery), when i pull the battery from phone and insert it again then i check from log file which I created on phone memory. By observing the log I found my Application's main method does not call after restarting.What can be the reason?
i think this question does not make any sense. After diagnosing we found that every thing was working fine, but the only problem was that, after restarting (by pulling battery) it takes some time to initialize memory card, and my db and log file is stored on memory card. After detection of problem i shifted my log file to phone memory and i found every thing was OK. Now i put some delay on the stating of application, every thing is working fine as required.

Preventing "Time Change" Cheating in Game [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there a clock in iOS that can be used that cannot be changed by the user
I know in many iOS games that have tasks that take time (i.e. "10 hours until animal done breeding"), one can go into "Settings" and change the time to speed up the completion of the task. In the game I'm developing, I don't want users to do this, so I'm trying to implement a system to prevent this type of cheating. I've put a lot of thought into this, but can't come up with a solution. Basically, my question is how do I keep track of time without relying on the system clock (which can easily be manipulated) for the purpose of preventing users from cheating?
transforming my comment into an answer.
Instead of relying on a user or device, rely on an external source for providing unbiased time. A time server, your server, etc. If you don't trust....
Instead of "X hours of real-world time", would "Y minutes of in-app time" work for you? You can pause/continue a timer when your app suspends/resumes.

Resources