tags:

views:

1017

answers:

4

I have an aesthetic UI element, a reflection, that works well on the iPhone 3Gs and iPod Touches, but is too slow on the 3G and prior. How best can I detect CPU speed so I can disable this function?

+7  A: 

Instead of trying to detect speed, you could find out what model of iPhone or iPod Touch your application is running on, and then disable the function if it is not an accepted iPhone/iPod type.

To do this, you could add the following to your application:

#import <sys/utsname.h>

- (NSString *) machineModel {
    struct utsname systemInfo;
    uname (&systemInfo);
    return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
}

Calling NSLog(@"Type: %@", [self machineModel]) will give you the hardware model.

Alex Reynolds
+4  A: 

See this post: http://www.iphonedevsdk.com/forum/iphone-sdk-development/4960-how-identify-device-user.html#post111621

I think that'll give you exactly what you are looking for.

Zoran Simic
+1  A: 

Personally, if the issue at hand is a reflection is running to slow on the sower devices, I would spend the time optimizing the reflection, rather than doing device detection. A simple reflection should not need to be that cpu intensive, if designed correctly the bulk of the work should be running on the GPU.

Brad Smith
I'm going to post the code and see if anyone here is good at optimizing. However, why the reflection speed impacts my app is because I am doing a reflection of a scrollview. As the scrollview scrolls, I call setNeedsDisplay on my reflection view in my scrollview delegate (scrollViewDidScroll). It works almost flawlessly on faster devices, but on the 3G and prior, the scrolling is jumpy.
mahboudz
A: 

What I ended up doing was to time one iteration of my "slow" routine. If it takes more than 0.5 seconds, I decide that the CPU is too slow and I turn it off.

In order to make the UI not confusing, I add a preference to toggle that routine, and if I turn it off, and the user selects, I display a message saying that the "feature" is CPU intensive and may some aspects of the application seem sluggish, and they may wish to leave it off. If they turn it on anyway, that is their choice. I will run this by my beta testers to see if I am making it too confusing.

Next step is optimization, but so far, I have not been able to make it much faster.

mahboudz