App Crash iPhone 5 and below - iphone

I released a simple game which works fine on iPhone 5s, 6, 6s and iPads. But when running on iPhone 5, 5c, 4S or 4, the app crashes at the point when this code happens:
let delay = Int(arc4random_uniform(UInt32(300)))*Int(NSEC_PER_SEC)/100
I get this error:
thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0)
I think it's really weird it only happens on iPhone 5 and below.

The maximum value of a 32 bits integer is 2 147 483 647.
Your delay value may be greater than that, so sometimes it will crash on 32 bits platforms like these devices you listed because Int won't be able to hold the value.

If the reason is because the Int cant hold the value then make it a UInt. This will double its maximum value.

Related

Backoff delay duration less than minimum value

Back off delay duration less than minimum value in flutter download .
Notification keeps on loading
This is caused by the limitation of FlutterDownloaderPlugin.java
The minimum value is 10 seconds .i.e. The time gap between two consecutive downloads.
Set a duration of 10 seconds for the next download to occur.
The issue only occurs in andorid simulator, but it works in real device.

get carrier name and signal strength return wrong value in iphone

i curious why i get wrong value to get carrier name and signal strength.
Here the code.
CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *car = [netinfo subscriberCellularProvider];
NSLog(#"Carrier Name: %#", car.carrierName);
[netinfo release];
Why i get value "carrier" instead of carrier i use?
this is code to get signal strength
void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
int (*CTGetSignalStrength)();
CTGetSignalStrength = dlsym(libHandle, "CTGetSignalStrength");
if( CTGetSignalStrength == NULL) NSLog(#"Could not find CTGetSignalStrength");
int result = CTGetSignalStrength();
NSLog(#"Signal strength: %d", result);
dlclose(libHandle);
as i kno, signal strength is in dBm value (in negative), but why the value above show positif value and now shown the signal strength?
is there any value mapping to present the signal strength on dBm
P.S i ran the program on the real iphone devices and still get wrong value.
any help would be appreciate.
Thanks.
About the carrier: Running your code on the simulator gives me nil while running on a device correctly says 2011-11-24 10:49:05.182 testapp[12579:707] Carrier Name: Vodafone.de, so the code is absolutely correct (running on iOS 5.0.1 using Xcode 4.2). Maybe your carrier didn't fill out some field correctly? In any case I would consider testing on another device or with another SIM card.
Concerning signal strength: As CTGetSignalStrength seems to be a rather undocumented API the values may be arbitrarily defined by Apple (and redefined as well). In any case this seems to be a RSSI value (received signal strength indication) which is more or less a positive number where 1 is the worst signal strength and upper is better. As such there is no predefined (documented and thus stable) available mapping to dBm values, a mapping would probably have to be created experimentally.
It is quite common that signal strength values are returned as integer numbers. The tricky point is the mapping to the corresponding dBm value. Usually the int values provide a resolution of 0.5, 1, or 2 dBm. The dBm values reported by the handset/modem usually range from -115 to -51 dBm for 2G (GSM/EDGE) and -120 to -25 dBm for 3G (UMTS/HSxPA) and represent the RSSI (received signal strength indicator).
E.g. the Android API uses the default 3GPP mapping (see Android reference).
Please take also into account that the baseband modem differs between the iPhone 4S (Qualcomm) and earlier models which used an Infineon Gold.

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.

Long Double on the iPhone

im working on an application that requires me to use a Long Double variable, which, in C/C++/ObjC, should be precise up to 15 floating values (1.123456789012345), the only issue is that on the iphone, i can only seem to display up to 6 places (1.123456) using
NSString *display = [NSString stringWithFormat:#"%Lf",value];
I was reading that the iphone bottlenecks these values but havent found out too much on it, anyone have any ideas how to get it to return 15 points like it should? thanks!
NSDecimalNumber will give you up to 38 digits of precision.
NSDecimalNumbers are not native long doubles, but some type conversions are supported.
See also This question.
Long double simply maps to double on the iPhone hardware. You unfortunately don't get the extra precision that you'd think you would. This tripped me up early on, because the iPhone Simulator will handle long doubles correctly, as it is running on a Mac.
As Charles suggests, you'll need to use NSDecimal or NSDecimalNumber to get that extra precision. Additionally, math involving those types will be free of the normal floating point issues you see when handling decimals.

How many 1024*1024 pngs can be load in openGL for iphone without having the app crash in the device ??

Approximately what's the maximum number of 1024x1024 32 bit .pngs which can be loaded at the same time with openGL in iphone ?, without risk of the app crashing.
And .pvr ? a much higher number ?
If I need a huge amount of textures in my game, is healthy to keep loading and calling dealloc to not overload the memory with all the textures ?
You should load textures as required and unload unused textures when your application receives a low memory warning.
To answer your maximum memory question, it seems that the iPhone 2G/3G gives memory warnings around the 20 MB mark and iPhone 3GS starts to give warnings around 128 MB.
1024 * 1024 * 32 bits = 4 MB
So that's about 5 textures loaded before you get warnings. 1024 x 1024 is quite large (it's the largest you can have AFAIK) for a texture, so if possible you should reduce their size.
Note: My warning threshold values aren't official, they're just from experience and from other questions on stackoverflow.
PVRTC can be used with either 2 or 4 bits per texel, which is a huge saving. It's not possible to give a specific number for the amount of texture memory which is safe to use. Apple really dropped the ball on this, see this and this articles from Noel Lopis.
Also remember that if you're using mipmaps it takes 33% more memory (each mipmap is 1/4 of the level above => 1 + 1 / 4 + 1 / 16... ~= 1.33).
EDIT: One more note PVRTC doesn't work well if you have a very distinct alpha mask that you want to preserve.
I hope when you say "and calling dealloc" you mean "and releasing those objects with -release" because you should never ever call -dealloc on any object yourself.