how to calculate battery time,3g game play etc,iOS - iphone

i want to calculate time for
3D gaming,3G Talk time,Video use,WiFi Internet,2G Talk time,Audio use and Standby depending on the current battery level.
There are many app do this, but i didnt found any resource to calculate that in iOS.
I calculated the battery level
[myDevice setBatteryMonitoringEnabled:YES];
float batLeft = [myDevice batteryLevel];
int i=[myDevice batteryState];
int batinfo=(batLeft*100);
now on the basis of batinfo,i need to calculate the time remaining for other parameters.
Thanks

Apple provide some data in device specification. You can use it for your calculation.
For example Apple say, app. 8 hours talk time on 3G (Iphone 5).
Now,
int batinfo=(batLeft*100);
int minutes3G=480; //minutes of 8 hour (static)
int talk3G=(minutes3G*batinfo)/100;
hour=talk3G/60;
min=talk3G%60;
lbl3Gtalk.text=[lbl3Gtalk.text stringByAppendingFormat:#"Remaining Time : %dh %dmin",hour,min];

Related

CLBeacon proximity always returning only .near and .far value but not .immediate

I am using estimote beacons for an iOS app and implemented CLLocationManager delegate method didRangeBeacons to determine the proximity of each beacon.
Based on the .immediate, .near, .far proximities, i have some functionalities written.
This was working perfectly before in iOS 11. After iOS 12 upgrade .immediate proximity is not at all getting called. Only .near and .far is getting called.
I searched a lot and couldn't find any solution for this. What could be the reason for not detecting .immediate alone even if i place the iPhone just above the beacon?
Check to see what the CLBeacon accuracy field returns. This is an estimated distance in meters, derived from RSSI and the measured power calibration value configured into the beacon. Basically, you will get an .immediate proximity if the accuracy is 0.5 meters or less. And you only get an accuracy of 0.5 or less if the RSSI (measured in dBm) is significantly stronger (less negative) than the measured power calibration value (also measured in dBm) configured into the beacon.
You may be able to get your device to return an .immediate value by adjusting the measured power calibration value configured into the beacon to be a more negative number.
The above suggestion of course, will not help it work the same way across both iOS 11 and iOS 12 if you really see that there is a difference between the two. I would be curious to hear if you can reproduce this difference with a second device.

estimating time remaining for full battery charge [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
time remaining until charge is complete,iOS
I am using below code to get the battery level
UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
float batLeft = [myDevice batteryLevel];
int i=[myDevice batteryState];
batinfo=(batLeft*100);
But i am not able to figure out, how to calculate/estimate the time remaining in full charge , i.e when battery level = 100%.
I m trying to get something like
time remaining full charge = 01:30:10
Suggestions is always appreciated.
Thanks
An example of battery specs on Apple's site, you would probably need to record all the devices and use conditions to see which one is which:
Talk time: Up to 8 hours on 3G, up to 14 hours on 2G (GSM)
Standby time: Up to 200 hours
Internet use: Up to 6 hours on 3G, up to 9 hours on Wi-Fi
Video playback: Up to 10 hours
Audio playback: Up to 40 hours
The code to get the percentage of battery left is:
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
float batteryLevel = [myDevice batteryLevel];
Thats all you can do, so anything else an app uses is guesswork and calculations on your half.
Credits -- copied from here, had to do it because you said it is "not what i needed" even though it is the exact answer.
So to conclude it is not possible using the native API, you must setup conditions to find what model the device is and do the calculations by using specs from apple's site.

What units does iOS GPS return speeds in?

I'm using the iPhone 4's built in GPS to return the date pos alt and speed.
However after looking for a long time I cant seem find what the speed is returned as, I know it's a double, but is this in meters per hour, feet, miles or what?
can anyone out there shed a clue???
thanks in advance.
Spriggsy.
Meters / second are the units of the speed
If you read the documentation, you'll find that the very first thing it tells you is what units it's in (metres per second).
If you read the EXIF tags standards doc, the allowable choices are K, M, or N for KpH, MpH, or Knots. The value Apple sticks in the GPSSpeed Field is however m/s while using K for the GPSSpeedRef (which violates the EXIF Standards)

How to balance start time for a multiplayer game?

I'm making a multiplayer game with GameKit. My issue is that when two devices are connected the game starts running with a slight time difference. On of the devices starts running the game a bit later. But this is not what i want. i want it to start simultaneously on both devices. So the first thing that i do is i check time of the beginning on both devices like this:
startTime = [NSDate timeIntervalSinceReferenceDate];
and this is how it looks:
361194394.193559
Then I send startTime value to the other device and then i compare received value with startTime of the other device.
- (void)balanceTime:(double)partnerTime
{
double time_diff = startTime - partnerTime;
if (time_diff < 0)
startTimeOut = -time_diff;
}
So if difference between two start times is negative it means that this device is starting earlier and therefore it has to wait for exactly the difference assigned to startTimeOut variable, which is a double and usually is something like 2.602417. So then i pause my game in my update method
- (void)update:(ccTime)dt
{
if (startTimeOut > 0)
{
NSLog(#"START TIME OUT %f", startTimeOut);
startTimeOut -= dt;
return;
}
}
But it unfortunately it doesn't help. Moreover it even extends the difference between start times of the devices. I just can't get why. Seems like everything i'm doing is reasonable. What am i doing wrong? How do i correct it? What would you do? Thanks a lot
As Almo commented, it is not possible to synchronize two devices to the same time. At the lowest level you will gnaw your teeth out on the Heisenberg Uncertainty Principle. Even getting two devices to synchronize to within a tenth of a second is not a trivial task. In addition, time synchronization would have to happen more or less frequently since the clocks in each device run ever so slightly asynchronous (ie a teeny bit faster or a weeny bit slower).
You also have to consider the lag introduced by sending data over Wifi, Blutooth or over the air. This lag is not a constant, and can be 10ms in one frame and 1000ms in another. You can't cancel out lag, nor can you predict it. But you can predict player movements.
The solution for games, or at least one of them, is client-side prediction and dead reckoning. This SO question has a few links of interest.

Cannot get CPU frequency in iOS 5?

This used to work in iOS 5 but does not seem to work any longer:
unsigned freq;
mib[0] = CTL_HW;
mib[1] = HW_CPU_FREQ;
sysctl (mib, 2, &freq, (void*) &len, NULL, 0);
Does anybody know an alternative?
Thanks.
Apple doesn't provide the CPU frequency for all hardware. For example, it was unknown for some time exactly what the clock rate for the A4 in the iPod touch 4g was.
I think the best you can do is determine what the device is, and construct a lookup table with the CPU frequencies you can find on wikipedia and so on. Then, if you can't probe the CPU frequency, look it up in the lookup table.