EXC_BAD_ACCESS when retrieving views from transition context on iPhone 4 - ios

I have the following code, which works perfectly on my iPhone 5 and all the iPhone simulators, but it crashes on my iPhone 4. I get EXC_BAD_ACCESS on the last line where I pass UITransitionContextToViewKey to my transition context.
I have a clean analyze and build, and the same happens for both UITransitionContextFromViewKey and UITransitionContextToViewKey.
My iPhone 4 is on iOS 7.1.2, my deployment target is 7.0, targeted build base SDK 8.0.
Anyone knows what to do here? thx.
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
// get transition parameters from context
UIView *containerView = transitionContext.containerView;
UIViewController *destinationViewController =
[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
if ([destinationViewController.title isEqualToString:#"ListController"]) {
// get source and destination views
UIView *sourceViewSnapshot = [self.view snapshotViewAfterScreenUpdates:YES];
UIView *destinationView = [transitionContext viewForKey:UITransitionContextToViewKey]; // EXC_BAD_ACCESS
// ...
}

The viewForKey method is iOS 8 and up, but the viewControllerForKey method is supported in iOS 7. A small change to your code gets the view in iOS 7:
UIView *destinationView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view;

From the documentation:
UITransitionContextToViewKey
Available in iOS 8.0 and later.
You can't run that code on iOS 7
You might want to add runtime system version checks and branch out to a iOS 7 compatible code at this point if you want to maintain compatibility with this version of the system

Related

Conditional code for iOS class availability

I am trying to add conditional code to prevent "Symbol not found" errors on an iOS 7 device when using an iOS 8 class, in this case UIBlurEffect:
dyld: Symbol not found: _OBJC_CLASS_$_UIBlurEffect
Even though the code within the conditional does not run (I do not see the "UIBlurEffect will be used!" log statement), I still get the error. If I comment the block out, it runs fine.
BOOL blurAvailable = NSClassFromString(#"UIBlurEffect") ? YES : NO;
if (blurAvailable)
NSLog(#"UIBlurEffect available");
else
NSLog(#"UIBlurEffect not available");
if (navBarBlurBool && blurAvailable)
{
NSLog(#"UIBlurEffect will be used!");
if (![viewController.navigationController.navigationBar viewWithTag:BLUR_NAVBAR_TAG])
{
// Code works on iOS 7 if this block is commented out:
[self storeOriginalNavBarImages];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
blur.frame = CGRectMake(0, -1 * statusBarFrame.size.height, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height + statusBarFrame.size.height);
blur.userInteractionEnabled = NO;
blur.tag = BLUR_NAVBAR_TAG;
[self.navigationController.navigationBar insertSubview:blur atIndex:0];
}
}
I don't understand - I would assume that if blurAvailable is false then the offending code should not run and I should not get the "Symbol not found" runtime error.
I'm using iOS 9.2 SDK. Xcode 7.2. Deployment target is iOS 7.0.
Please make sure that blurAvailable is really NO on iOS 7.
Maybe the class is available on iOS 7 but not marked as such in the documentation. They might have introduced it in iOS 7 as a private class (just hiding it in the doc and headers).
Try testing another class marked as "unavailable on iOS 7" like UIVisualEffectView.
From a comment in this question, the answer is to add UIKit as an Optional dependency in "Build Phases" -> "Link Binary with Libraries". I can now run the conditional iOS 8 code without errors on the iOS 7 device.

I can not load SKView scene in iOS 7

I have a game in AppStore made with SpriteKit. Its deployment target is 7.0. Compile and runs fine until I upgraded to XCode 7.3.
I don't have any problems with IOS 8 or 9 but with 7 it simply does not load my scene.
My code to load my scene is:
#implementation levelsViewController {
SKView *_skView;
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
// Configure the view.
if (!_skView) {
_skView = [[SKView alloc] initWithFrame:self.view.bounds];
LevelsScene *scene = [[LevelsScene alloc] initWithSize:_skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
_skView.showsFPS = NO;
_skView.showsNodeCount = NO;
_skView.showsPhysics = NO;
// AFTER A WHILE< NEVER SHOW THE SCENE. I DONT HAVE ANY PROBLEM WITH IOS 8 or later but with 7 :(
[_skView presentScene:scene];
[self.view addSubview:_skView];
[self.view sendSubviewToBack:_skView];
...
}
Any help would be appreciated!
Finally found the workaround.
My Scene use this class from github https://github.com/zackhsuan/ZKPulseView.
I don't understand why, but this routine works perfect until XCode 7.3. The behavior is weird, because it's works perfect for iOS 8 and 9 but in 7, show the effect perfect, but when I press the button with effect and the scene call something with spritekit got this strange behavior.
So, just does not used this routine exclusively for ios 7 and works.

preferredContentSize not working in ios 7?

I am using modalPresentationStyle of type UIModalPresentationFormSheet to show my view.I want specific size of the view so using preferredContentSize which working in iOS 8 and showing exact how I wanted but same breaks for iOS 7 it's come as full sheet.View size changed.
Where as I wanted like below image
Any idea?
Please check below conditional code for iOS 8.x and iOS 7
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0"))
{
modalController.preferredContentSize = CGSizeMake(frameSize.x, frameSize.y);
}
else
{
modalController.view.superview.frame = CGRectMake((screenWidth - frameSize.x)/2, (screenHeight - frameSize.y)/2, frameSize.x, frameSize.y);
}
Hope this will help you.

iOS 8 issues in showing UIView

I have a custom UIView in my application which was working correctly in iOS 7.1 but after upgrading the device to iOS 8, i start having issues with Showing it.
1) Orientation issues
2) On keyboard show issues
Screenshots from iOS 7
How Custom UIView appear on iOS 8
Here's the code sample:
1) Calling the custom UIView
CustomIOS7AlertView *alertViewiOS7 = [[CustomIOS7AlertView alloc] init:NULL];
[alertViewiOS7 setContainerView:[self Calculator_Create]];
[alertViewiOS7 setButtonTitles:[NSMutableArray arrayWithObjects:languageSelectedStringForKey(dataObj.languageBundle, #"Close"), languageSelectedStringForKey(dataObj.languageBundle, #"Add"), nil]];
[alertViewiOS7 setUseMotionEffects:true];
[alertViewiOS7 show];
2) CustomIOS7AlertVIew class Code
https://drive.google.com/folderview?id=0B-EraWQtN1hNfmtoUXZHLXNPREdrU1QwVkdwTDNCWDhHYXk5X3hNSjdOQ3FZM3k4T0hyZUk&usp=sharing
Use UIAlertController because UIAlertView has been deprecated in iOS 8.

IBM Worklight 6.0 - App Center on iOS7 fails to open

After building the IBMAppCenter application with Xcode 5.0.2,
When running the .ipa on an iPhone it unfortunately doesn't work.
When clicking the app it opens up, shows the splash image for a few seconds, but then closes without throwing an error.
Is this a known error?
Make sure that you have followed the instructions on how to enable the AppCenter application for iOS 7, as detailed in the following IBM technote: http://www-01.ibm.com/support/docview.wss?uid=swg27039574
I'd even say to make sure you are running the correct version of Worklight.
Please carefully read the technote.
Copy/paste:
Enable the Application Center Client
Complete the following steps to enable your Application Center Client to run on iOS 7:
Import the App Center project into Eclipse as the documentation states.
Use the Worklight Studio wizard to create another Worklight project and add an iPhone environment.
Copy the apps/appName/iphone/native/WorklightSDK/libWorklightStaticLibProject.a file to the App Center project. Overlay the existing file by using the same name.
Add the following code in the CDVMainViewController Worklight generated class (CDVMainViewController.m). This code handles the iOS 7 status bar design change.
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
- (void)viewWillAppear:(BOOL)animated
{
CGFloat version = [[UIDevice currentDevice].systemVersion floatValue];
if (version >= 7) {
// iOS 7 or above
CGRect oldBounds = [self.view bounds];
CGRect newViewBounds = CGRectMake( 0, -10, oldBounds.size.width,
oldBounds.size.height-20 );
CGRect newWebViewBounds = CGRectMake( 0, -20, oldBounds.size.width,
oldBounds.size.height-40 );
UIColor *headerColor =
[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f];
[self.view setBackgroundColor:headerColor];
[self.view setBounds:newViewBounds];
[self.webView setBounds:newWebViewBounds];
}
[super viewWillAppear:animated];
}

Resources