Application crashing in iOS 7 - iphone

I am trying two same statements and running them on iOS 5.1 simulator and on iOS 7 simulator but they both are returning different values and my code is
BOOL isSelected = YES
NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
On debugging in respective simulators:
while running on iOS 5.1 simulator :
selectedIndex = (null)
while running on iOS 7 simulator :
selectedIndex = #"1"
and if I try :
isSelected = NO:
On debugging in respective simulators:
while running on iOS 5.1 simulator :
selectedIndex = (null)
while running on iOS 7 simulator :
selectedIndex = #"0"
Any help would be appreciated.

Related

The text in my date picker shows in the simulator but not when I run it on my ios14 phone

Simulator screenshot
ios 14 iphone screenshot
Anyone else experiencing this bug?
You need to implement preferredDatePickerStyle.
if #available(iOS 13.4, *) {
datePicker.preferredDatePickerStyle = .inline
}
To know more you can check this: https://medium.com/better-programming/introducing-swifts-new-modern-date-picker-37bb5e0a106

iphone iCloud app crashes when compiling on iOS 4

I'd like to use an iCloud, but when I compile the app on iOS 4.3 Simulator it crashes.
dyld: Symbol not found: _OBJC_CLASS_$_NSMetadataQuery
What should I do to make it working on iOS 3, 4, and 5?
my sulotion is:
Where have NSMetadataQuery change to id: ex
normal : - (void)loadData:(NSMetadataQuery *)query;
change to: - (void)loadData:(id)query;
normal: #property (retain, nonatomic) NSMetadataQuery *query;
change to: #property (retain, nonatomic) id query;
and check iCloud available:
if ([[NSFileManager defaultManager] respondsToSelector:#selector(URLForUbiquityContainerIdentifier:)]) {
NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (ubiq) {
// Code for access iCloud here
}
}
When use NSMetadataQuery:
id _query = [[NSClassFromString(#"NSMetadataQuery") alloc] init];
// Some code here
[_query startQuery];
Have fun (^_^)
The usual way would be to compile it with iOS 5 SDK and setting the deployment target to the oldest iOS Version you'd like it to work with. It's up to you though to check at runtime on which classes and methods are available to the current system. A user on iOS 4 for example will not be able to use functions that only ship with iOS 5.
To check the availability of classes do:
if ( NSClassFromString(#"NSMetadataQuery") != nil ) {
//do stuff with NSMetadataQuery here
}
To check the availability of methods do:
if ( [myObject respondsToSelector:#selector(doSomething)] ) {
//call doSomething on myObject
}
These API has been launched with the ios5 so you cann't run it on the simulator 4 or below but for posting you can set the minimum deployment target of ios family it should support .

Compiler errors after upgrading to XCode 4

I've upgraded xcode and ios sdk to the latest version (xcode 4.0 / ios sdk 4.3) and now I'm getting compiler errors on a project that was building before.
This is the code:
- (void)layoutSubviews
{
int w = 320;
int h = 480;
float ver = [[[UIDevice currentDevice] systemVersion] floatValue];
// You can't detect screen resolutions in pre 3.2 devices, but they are all 320x480
if (ver >= 3.2f){
UIScreen* mainscr = [UIScreen mainScreen];
w = mainscr.currentMode.size.width;
h = mainscr.currentMode.size.height;
if( ver >= 4.0f ) {
float scaleFactor = mainscr.scale;
// this will scale the OpenGLView for retina screens
self.contentScaleFactor = scaleFactor;
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.contentsScale=scaleFactor; //new line
}
}
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer *)self.layer];
setOpenGLSize(w,h);
[self drawView:nil];
}
And these are the errors:
error: property 'scale' not found on object of type 'UIScreen *' [2]
error: property 'contentScaleFactor' not found on object of type 'EAGLView *' [2]
error: property 'contentsScale' not found on object of type 'CAEAGLLayer *' [2]
I have Base SDK setted to iOS 4.3 and deployment target to iOS 3.0
If i set deplyment target to 4.3, the error dissapear, but I want the app to run on 3.0 and above.
What's wrong with the code or the project?
"I have Base SDK setted to iOS 4.3 and deployment target to iOS 3.0"
So it is warning you that the properties scale, contentScaleFactor and contentsScale were introduced in 4.0 and you can't use them in 3.x.
If you really want to deploy to 3.x (and everything I've seen says it is of questionable worth to make your app support it, especially since the unification of iOS post-iPad2) then you have to work around those properties not being there.

iPhone 4 detection... on simulator

I need to detect if the user is using an iPhone 4, but I need this to work on the simulator (cause Apple forgot my country and there's no sign of iPhone 4 here soon).
I found this
http://www.clintharris.net/2009/iphone-model-via-sysctlbyname/
but running this on the simulator it does not detect the correct version. I mean, Xcode 3.2.3 has two simulators (3G/3GS and 4). I was expecting the detection method to tell me the correct version I am using... but instead it tells me "iphone simulator"...
Is there any way to do that?
thanks.
You don't need to detect the system version in your case.
Suppose an image is named foo.png, then you just need to add
foo~ipad.png for iPad
foo#2x~iphone.png for iPhone 4
and load the image with [UIImage imageNamed:#"foo.png"]. See the iPhone Application Programming Guide for detail.
I think it would be better to check for the feature you require, rather than a specific device. This is certainly what Apple recommends, as it gives you insurance when new devices roll around!
In this case, would it work to check the size of the screen, and use that to determine if you need to scale your image?
[[UIScreen mainScreen] bounds]
Hardware Availability and State
If a hardware feature (for example,
a gyroscope) is not available on a
device, calling a start method related
to that feature has no effect. You can
find out whether a hardware feature is
available or active by checking the
appropriate property; for example, for
gyroscope data, you can check the
value of the gyroAvailable or
gyroActive properties.
Use
#property(readonly, nonatomic, getter=isGyroAvailable) BOOL gyroAvailable
of class CMMotionManager.
See
#property (nonatomic, readonly, retain) NSString *systemVersion;
// It equal to #"4.0" on iOS 4.0
and
#property (nonatomic, readonly, retain) NSString *model;
// Possible examples of model strings are #”iPhone” and #”iPod touch”
of class UIDevice.
From Erica Sudan:
- (NSString *) platform
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
/*
Possible values:
"iPhone1,1" = iPhone 1G
"iPhone1,2" = iPhone 3G
"iPhone2,1" = iPhone 3GS
"iPhone3,1" = iPhone 4
"iPod1,1" = iPod touch 1G
"iPod2,1" = iPod touch 2G
*/
NSString *platform = [NSString stringWithCString:machine];
free(machine);
return platform;
}
Or, if you just need to detect if it's a high res screen, you can use:
UIScreen *screen = [UIScreen mainScreen];
BOOL isHighRes;
if ([screen respondsToSelector:#selector(scale)]) {
isHighRes = ([screen scale] > 1);
} else {
isHighRes = NO;
}
Mike, you can know if the user is using an iPhone 4 by using preprocessor instructions. For example:
#ifdef __IPHONE_4_0
// Do some work for iPhone 4 device
#else
// Do some work for non iPhone 4 device
#endif
I hope it can help you.

How to detect an iPhone app is running on iPhone 4 device or not?

I try to update an iPhone application to support the larger screen resolution on iPhone 4. How to detect if my app is running on iPhone 4 or not?
Thanks in advance.
i can trace my iPhone 3GS through this code
struct utsname systemInfo;
uname(&systemInfo);
NSLog(#"%#", [NSString stringWithCString:systemInfo.version
encoding:NSUTF8StringEncoding]);
i hope it will work for iPhone 4
You could try using this method
-(NSString *) getDeviceType {
return [UIDevice currentDevice].model;
}
Or just get it like this:
NSLog(#"%#", [UIDevice currentDevice].model);
To check if a device is retina capable do the following:
BOOL result;
if ([[UIScreen mainScreen] scale] == 2.0) result = TRUE; else result = FALSE;