iOS5 CMMotionManager startDeviceMotionUpdatesToQueue: fails on iPhone3GS - iphone

I have a software-hardware related issue that I'm trying to troubleshoot. My app was developed for iPhone4, iOS5 and uses Core Motion framework to process accelerometer and gyroscope data in real time. The app fails when running on iPhone 3GS with iOS5
My main core-motion method looks like this:
[motionManager startDeviceMotionUpdatesToQueue:motionQueue withHandler:^(CMDeviceMotion *motion, NSError *error) {
//notify calibration delegate
if(calibrationDelegate)
{
[calibrationDelegate collectCalibrationMotionData:motion];
}
//a lot more processing
}
I have reports that iPhone3GS does not return yes to isGyroAvailable, while iPhone4 returns yes.
BOOL accelerometerAvailable = (motionManager.isAccelerometerAvailable)?YES:NO;
BOOL gyroscopeAvailable = (motionManager.isGyroAvailable)?YES:NO;
if(!accelerometerAvailable && ! gyroscopeAvailable)
{
//handle error
remoteControlState = kRemoteControlStateError;
}
I've painfully discovered that Apple sells my app to customers with iPhone4, 4s AND 3GS. The app does not work for customers with iPhone 3GS because the call above does not seem to pass the motion objects to the calibration delegate.
I do not have iPhone 3GS to test the app on, so I have a few questions:
Is it possible to specify anywhere in the XCode project properties
that I want my app to run ONLY on iPhone4 and above? (or devices with gyroscope available?)
Where can I find more information on iOS5 quirks like the one above
to better understand how iPhone3GS differs from iPhone4?

Is it possible to specify anywhere in the XCode project properties that I want my app to run ONLY on iPhone4 and above? (or devices with gyroscope available?)
Yes, you would specify such dependencies in the UIRequiredDeviceCapabilities key of your Info.plist (gyroscope would be the requirement in this case).
However, for a released app, it's unfortunately impossible to add new requirements.

Related

Adapt app from iOS7 to iOS6

I wrote my application for iPhone in xcode 5.0 and it supports only 7 ios.
How can I make it available for ios 6?
Also interested in how to prevent applications load on ipad?
First question: Make sure your deployment target is 6.0, don't use API's that are iOS 7 only, or check by using
if ([someObject respondsToSelector:#selector(ios7onlymethod)] {
// do your iOS 7 only stuff
} else {
// Fall back to iOS 6-supported ways
}
Or use
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) {
// do your iOS 7 only stuff
} else {
// Fall back to iOS 6-supported ways
}
New frameworks you want to use should be marked as optional in Xcode; to do that select your target, click general, and scroll to the "Linked Frameworks and Libraries" section.
What's really cool is that classes in frameworks marked as optional are replaced with nil on versions of iOS that don't have them. So suppose you write some code like this, using a class from the Sprite Kit framework, new in iOS 7:
SKSpriteNode *spriteNode = [SKSpriteNode spriteWithImageNamed:#"mySprite"];
On iOS 6, when the linker, which "links" frameworks to apps (apps don't copy frameworks, they just get them from the system), sees SKSpriteNode in your code, and the framework is marked as optional, that line of code will be replaced by this:
... = [nil spriteWithImageNamed:#"mySprite"];
Sending messages to nil in Objective-C does absolutely nothing, so the above code doesn't crash. No problem. So instead of lingering your code with if-statements checking for the existence of a class, you can just go with the flow and let the dynamic linker do the work.
Further reading:
iOS 7 UI Transition Guide: Supporting iOS 6
Supporting Multiple iOS Versions and Devices
Second question: There is no way to say that you want your app to only run on iPhones and iPod touches. You can require things that are specifical to the iPhone and iPod touch (like a certain processor architecture or the M7 motion coprocessor) but Apple won't like it if you require the M7 chip to exclude a certain device when you don't even need it. You should probably think about why you don't want your app to run on iPads.

Application Platform Specification

I am designing an app for iphone & ipod the client wants the Some of the UI Specification for iphone and ipod to be different so i decided to create different XIB Files for iphone and ipod as in universal apps for iphone and ipod but the problem is that i am not able differentiate between iphone and ipod on run time is there any way to check platform on runtime so as to load different Nib Files on runtime
If there is any code or tutorial please guide me to the link
Thanks in advance
[[UIDevice currentDevice] model] looks like the right source for this Information. You can check it if it contains iPod Touch or iPhone or.....
Check the model property of UIDevice class
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html
However, if you switch on that string, be aware that the simulator shows up as a separate device.
This:
NSString* model = [[UIDevice currentDevice] model];
NSLog(#"model: %#", model);
Outputs:
2011-10-25 08:44:30.794 Craplet[921:b303] model: iPhone Simulator
I think this was already asked several times .)
NSString *dtype = [UIDevice currentDevice].model;
if([dtype isEqualToString:#"iPhone"])
{
// iphone
}
Possible examples of model strings are #”iPhone” and #”iPod touch”

Apple gamecenter available test returns YES on iphone 3g

I'm making a game with gamecenter support. I want to diable a button for iPhone 3g or older devices. But my 3g test device says, that gamecenter is available and the matchmaking view show up. The user will never get authenticated. I use the snippet from apple to check, if gamecenter is available. It should return NO on devices older than 3gs
-(BOOL)isGameCenterAvailable {
// check for presence of GKLocalPlayer API
Class gcClass = (NSClassFromString(#"GKLocalPlayer"));
// check if the device is running iOS 4.1 or later
NSString *reqSysVer = #"4.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osVersionSupported = ([currSysVer compare:reqSysVer
options:NSNumericSearch] != NSOrderedAscending);
return (gcClass && osVersionSupported); }
Does anyone do it better than apple?
Apparently, there is more to detecting Game Center support than just checking for the existence of the API. According to Optionally Supporting Game Center In Your Game, in addition to checking for the APIs you'll also need to authenticate the player:
iOS 4.1 may be installed on some
devices that do not support Game
Center. On those devices, the
isGameCenterAPIAvailable function
defined Listing 1-1 still returns YES.
The next step in confirming whether
Game Center may be used on the device
is to attempt to authenticate the
local player; on devices that do not
support game center, your game
receives a GKErrorNotSupported error.

How do I build a game that only supports Game Center if it's available on the iPhone?

I'm about to begin building an iPhone game that will make use of Game Center Achievements and high scores, but I'd also like to have a version that works on iPhones that don't have Game Center (i.e. iOS version < 4.1). Can I have two versions of the same app in the app store, one for game center, one for without? Or should I design the app such that if the iPhone doesn't have Game Center, it won't make use of it, and if it does, it will make use of it?
I'm going to continue researching this, just thought I'd post this question and get some feedback in the meantime. Thanks so much!
Here's the definitive response I received from one of the Apple engineers...
"We'd recommend making one version of the app which dynamically detects whether Game Center is available and uses it (or not) based on that."
Maybe create a game without it, then create the capabilities for the game center, but disable them, and only enable them if they have the right version.
I am doing the same thing. If you have GameCenter capabilities, you can use the features. If you don't, you can't.
I would not program a game without and then add it later. In my case I disable Multiplayer for non-GC users.
Also, you may want your game to work if the device has GC capabilities, but the user cannot, for whatever reason, connect to GC currently.
You can use the following function to detect if the device supports Game Center:
BOOL isGameCenterAvailable()
{
// Check for presence of GKLocalPlayer API.
Class gcClass = (NSClassFromString(#"GKLocalPlayer"));
// The device must be running running iOS 4.1 or later.
NSString *reqSysVer = #"4.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending);
return (gcClass && osVersionSupported);
}
However I found that a lot of people have not updated to iOS 4.1 or are naive about Game Center. The number of users in my game is quite small even though there are so many downloads. I was actually considering moving over to Open Feint which is very much easier to implement than Game Kit and also supports older devices.

How do I run a universal app on the iPhone 3.1.3 simulator?

I'm working on a new app that I want to be universal for the iPhone and iPad. I started out with the "Create a Window-based app" wizard, and it created separate app delegates in "iPhone" and "iPad" groups. Since I already was quite familiar with iPhone dev, I did that part of my project, and now I'm ready to do some iPad stuff.
So... I started out by adding a UISplitViewController to my iPad delegate, switch the Active SDK to 3.2, and it works! But when I switch back to 3.1.3, and try to run it in the simulator, Build and Go fails. For starters, I see:
...path.../iPad/AppDelegate_Pad.h:13: error: expected specifier-qualifier-list before 'UISplitViewController'
I've got my Base SDK set to 3.2 and my Deployment Target set to 3.1.3. I thought that was enough. But I also have found in the documentation this method to conditionally compile:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
MyIPadViewController* vc;
// Create the iPad view controller
#else
MyIPhoneViewController* vc;
// Create the iPhone view controller
#endif
So do I need to do this everywhere? It seems like an awful lot of code to add (that I'll be getting rid of in a short time for 4.0 anyway) so I feel like I must be doing something wrong. And, I don't even have any idea how this works for things like #property or #synthesize declarations.
tl;dr version of the question - did I miss a setting somewhere?
I use this C function to help keep the code concise:
BOOL isPad() {
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
}
Another thing I do, when I have different xib files for iPhone vs iPad. I have a stripPadSuffixOnPhone() function that helps keep the code simpler:
// Load/create the Delete table cell with delete button
self.deleteCell = [Utilities loadNib:stripPadSuffixOnPhone(#"DeleteCell~ipad")
ClassName:#"DeleteCell"
Owner:self];
Things like that can make coding more straightforward and a lot less conditionals. Still have to test everything twice though.
Quite the opposite. A universal app runs the same binary on iPhone and iPad so you cannot use conditional compilation to differentiate between the two version. But you need to use the macro Apple cites in the documentation:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// iPad-specific code
} else {
// iPhone-specific code
}
Here's what works for me:
Build your app using SDK 3.2.
Switch the active SDK to iPhone Simulator 3.1.3 (or whatever).
From the Run menu select Debug (not Build and Debug).
The binary built under 3.2 will be installed in the 3.x simulator without rebuilding. When you are finished don't forget to set your active SDK back to 3.2.