Iphone dev ios not picking up 2x images in ray's application - iphone

I have downloaded ray wenderlich's code for apns application from this link
http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2
now i converted that project of ray's to tab bar application project, now i am having a problem with tab bar image. i added x and 2x resolution images in my images folder of project, and doing this in view will appear
AppDelegate *delegate2 =(AppDelegate *) [[UIApplication sharedApplication] delegate];
for(UIView *view in delegate2.tabBarControler.tabBar.subviews) {
if([view isKindOfClass:[UIImageView class]]) {
[view removeFromSuperview];
}
}
[delegate2.tabBarControler.tabBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"home.png"]] autorelease] atIndex:0];
the 2x resolution image which is home#2x.png, it is not being picked by ios 5 device (ipod 4) i know that the operating system (ios 5) automatically senses the 2x image and pick it, but in my case its not happening, rather its picking the x resolution image and there is a white line showing under tab bar, i am stuck here , please guide me thanx and regards Saad.

Lets run through some basics to see where something may have gone wrong;
Put the following line in your code, just after that and see what it prints out;
NSLog(#"Image scale : %f",[[UIImage imageNamed:#"home.png"] scale]);
If it prints out 'Image scale : 2.000000', that means the #2x image has been correctly identified and loaded by the app.
Also;
Delete both images, clean the project, add them and try rebuilding
Make sure the case of home.png and home#2x.png match exactly
If you're trying this on a simulator, Reset the simulator and try again.
If you already have a previous build on your device, delete it and try again.

Related

First view appears as black?

I have a program where I'm working with user authentication and alert views. the problem is quite strange. Every other time I launch the application, the first view appears as normal, and then black, and then back to normal, and so on and so forth.
Launched once:
Launched twice:
Here's the storyboard:
Functionally, it's both the same, but I have no idea what could be causing this problem!
Addition:
The alert is called on viewdidappear.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self presentAlertViewForPassword];
}
Addition 2 (build settings) (simulator is iphone 4):
Where do you have the AlertView show method? I think this could be because when you press the home button while you are at the UITableViewController and then you launch the app. This is where it starts from.
Do you have the login AlertView code in your applicationDidFinishLaunch?
This black screen seems your alert's view screen. You can set its background image. Do one thing
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIImageView *iV = [[UIImageView alloc] initWithFrame:self.view.bounds];
iV.image = [UIImage imageWithNamed:#"imageNameHere"];
[self.view addSubView:iV];
[self presentAlertViewForPassword];
}
Set that Christmas Keeper image on view's background. Hope it helps. Also check your splash screen's image. Search default.png in search box of xcode may be this is different or may be there is two default.png. Just a guess :)
Edit after notice your comment: the launch image is basically a uiimageview on the first page with an image in my directory
So I think that black screen is your launch image because it appears before appearing the first view of your app. You didn't set it yet. Please include a default.png image into your project and it should be same as your first View's `imageView' image.

iPhone screen shifts when entering foreground

I've noticed that when my iPhone app enters the foreground after being suspended on an iPad2 (iOS version 4.3.3), the iPhone screen seems to shift up by a small amount after a split second. My understanding is that iOS takes a snapshot of the screen before suspending the app so it can quickly bring it back up when resuming, but it's not clear to me why it would be shifted. The status bar placeholder and iPhone image don't shift up, only the rest of the iPhone screen does. I don't see this problem in the 5.0 simulator.
Any ideas what's going on or how to fix this? Thanks
When the app loads, it displays the default.png file that you have in your app bundle. If you have this image the same as whatever the first screen of your app is (which apple suggests that you should do) then it is displaying this image, and then the actual screen once the app is done initializing. You can edit the png file by shifting up a pixel or two (you'll just have to guess and check to see exactly what you need).
The other possibility is that your default.png isnt the right size, so it is being resized when the app actually starts. Check that the dimensions are correct for the device you are testing on.
Setting the status bat to initially hidden caused this for me.
Status bar is initially hidden YES
This fixed it
- (void) setStatusBarVisible: (NSTimer *)timer
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(setStatusBarVisible:) userInfo:nil repeats:NO];
}
It appears that setting then reseting (after a short delay) the status bar addresses this issue.
This fixes it but it shouldn't happen in the first place.
yes it happens when you come again to foreground. it happens with me & i have solved this issue by using
(void)layoutSubviews
that means i draws the things in layoutSubviews method which shifts & it works fine.
for more information on this check my problem & solution

How do I detect orientation on app launch for splash screen animation on iPad!

Hi I have an app and I have two *.pngs for default splash screen:
Default-Landscape.png
Default-Portrait.png
What I want is to animate this default splash screen away when my app is loaded and ready to go.
To achieve this I would normally present an UIImageView with either default-landscape or default-portrait (depending on the device orientation), keep it on screen for a certain time and then animate it away.
My problem is that if I call [[UIDevice currentDevice] orientation] in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
The answer is always that the device is in portrait orientation even if I clearly have it in landscape. I tried this in simulator and on the device as well and the behaviour is the same.
Does anyone know a fix for this or maybe some other approach?
Thanks!
I had troubles with this and I solved it by making one image 1024x1024 and setting the contentMode of the UIImageView to UIViewContentModeTop, then using left and right margin autoresizing. So long as your portrait and landscape default images are the same layout then this will work fine.
Just to clarify here's what I used:
bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:SplashImage]];
bgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
bgView.contentMode = UIViewContentModeTop;
To get around this problem I installed the splash image view inside of a view controller that allowed both orientations. Even though the device reported the wrong orientation at startup, the view controller seems to get the right one.
You can use UIApplication statusBarOrientation as follows:
if ( UIDeviceOrientationIsLandscape( [[UIApplication sharedApplication] statusBarOrientation] ))
{
// landscape code
}
else
{
// portrait code
}
Maybe you could show a blank view with black background at start time and place [[UIDevice currentDevice] orientation] into this view's viewDidAppear and start your splash screen from there?
Another solution would be to read the accelerometer data and determine the orientation yourself.
To know at start what is the orientation (UIDevice orientation don't work until user have rotate the device) intercept shouldAutorotateToInterfaceOrientation of your View Controller, it is called at start, and you know your device orientation.
There are certainly times when you want to transition from the loading image to something else before the user gets control of your app. Unless your app is really simple, going from loading image to landing page probably won't be sufficient without making the app experience really suck. If you ever develop a large app, you'll definitely want to do that to show progress during setup, loading xibs, etc. If an app takes several seconds to prepare with no feedback, users will hate it. IMO, there's nothing wrong with a nice transition effect either. Almost nobody uses loading screens the way Apple suggests to. I don't know which apps you looked at that showed the "empty UI" type loading screens they suggest. Heck, even Apple doesn't do that except in their sample code and none of my clients would find that acceptable. It's a lame design.
Only the first view added to the window is rotated by the OS. So if you want your splash screen to automatically rotate AND your main view is rotatable then just add it as a child of that view.
Here is my code for fading out the appropriate splash screen image:
// Determine which launch image file
NSString * launchImageName = #"Default.png";
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
launchImageName = #"Default-Portrait.png";
} else {
launchImageName = #"Default-Landscape.png";
}
}
// Create a fade out effect
UIImageView* whiteoutView = [[[UIImageView alloc] initWithFrame:self.window.frame] autorelease];
whiteoutView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
whiteoutView.autoresizesSubviews = YES;
whiteoutView.image = [UIImage imageNamed:launchImageName];
[[[self.window subviews] objectAtIndex:0] addSubview:whiteoutView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
whiteoutView.alpha = 0.0;
[UIView commitAnimations];
Note: You'll have to update it to support hi-res screens.
It sounds like you're not using the launch image the way Apple recommends in the iOS HIG. It specifically calls out that you should not use it as a splash screen, but rather as a skeleton version of your actual UI. The net effect is that your app appears to be ready just that much faster.
The suggestions that you could draw a splash screen yourself after the app has launching in viewDidAppear or similar also are missing the basic purpose of a launch image. It's not a splash screen. If your app is ready, let the user interact with it, don't waste their time drawing a splash screen.
From my five minute survey of Apple apps and third-party apps, everyone showed a portrait launch image, loaded the portrait version of the UI, and then rotated to landscape. It's been a while since programming on iOS, but I think this mirrors the order of the method calls -- first your app gets launched, then it is told to rotate to a particular orientation.
It might be a nice enhancement request to file with Apple though :)

iphone - grabbing the contents of the main screen

I have a specific function on an app that is intended to work on iPhone 4 and iPad. I don't have an iPad yet (because Apple forgot my country), so I have to test it on simulator.
I have a method that needs to grab the contents of the main screen as a CGImageRef.
I have this method:
- (CGImageRef)takeScreenshot {
UIWindow *theScreen = [[UIApplication sharedApplication].windows objectAtIndex:0];
UIGraphicsBeginImageContext(theScreen.frame.size);
[[theScreen layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenshot.CGImage;
}
When I compile and test the iPhone version of my app for the iPhone, it works perfectly. But when I compile and test the iPad version on iPad simulator, it returns a black screen.
For it to work, I have to change the "objectAtIndex:0" to "objectAtIndex:1" on the second line.
Is there any logic for this or it is just a simulator bug? As far as I know, index 0 is always the main screen.
Is there any other way to capture the main screen content from another class?
thanks in advance.
Maybe use the keyWindow to get the correct window directly?
UIWindow *theScreen = [[UIApplication sharedApplication] keyWindow];
For the country problem - consider ordering one from another country. ;-)

iPad rotation bug when using MPMoviePlayerViewController

Issue summary
Changing the orientation of an iPad device or simulator while playing a video using MPMoviePlayerViewController results in an inconsistent rotation state upon dismissal of the video player. This is a known bug in iPad SDK 3.2, documented at http://www.openradar.me/8012810
Sample project
I have prepared a minimal sample project using the View-based Application template from Xcode 3.2.2, using the following code to launch the player
NSURL *movieUrl = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];
[self presentMoviePlayerViewControllerAnimated:player];
[player release];
The code is available on GitHub at http://github.com/adamalex/FullScreenMovie or direct download using http://github.com/adamalex/FullScreenMovie/zipball/master
Steps to reproduce
Obtain the project using the information above
Launch the project with the iPad simulator or device
Tap the button to begin playing the video
Rotate the iPad by 90 degrees
Dismiss the video
Note the UIStatusBar is out of sync with the application UI
Objective
I have contacted Apple and they have confirmed this is a bug that is being investigated. I would like to discuss temporary workarounds that use public APIs safe for submission to the App Store. I am going to open a developer support case with Apple as well and will report back with my own progress.
Successful response from Apple Developer Technical Support!
This is a known bug and a we're received a number of duplicate bug reports and so iOS engineering is aware of the issue and we do have a temporary workaround as suggested by iOS engineering.
You will need to implement this in the view controller which presents the movie player.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[self performSelector:#selector(fixStatusBar) withObject:nil afterDelay:0];
}
- (void)fixStatusBar {
[[UIApplication sharedApplication] setStatusBarOrientation:[self interfaceOrientation] animated:NO];
}
While this is somewhat ugly, it should fix the issue for now. It would be recommended to remove this code once the bug is fixed in the system.
This took care of the issue completely for me, and you can revisit http://github.com/adamalex/FullScreenMovie for the code with the fix applied.
This also solves an iPhone/iPodTouch rotation issue that I was struggling with. I am developing a universal app in which each view displays a different image depending on whether the device is in portrait or landscape orientation. Buttons are used to navigate between views.
If the app is running on the device and a portrait view is rotated to landscape, my image switching takes place. If the device is then placed flat on a table top and the button is tapped to display the next view, the view appears in landscape but shows the portrait image instead. I solved the problem by forcing a portrait view to appear by detecting for face up and down, but Apple's code solved this problem (as well as the similar movie problem I was also experiencing).
Many thanks for reporting the bug - I assumed it was just my bad coding...