iPad simulator just shows black screen - iphone

I am developing an app in Xcode, I got it working and was putting some finishing touches.
Then I upgraded Xcode to the latest version, changed a bit the code for the Autorotate options (my app shouldn't autorotate) and fiddled with the supported rotation (landscape vs. portait).
Then suddenly my debug in iOs simulator just shows a black screen. The app builds fine but nothing is shown in the simulator....
And I can't really understand why...
Using Xcode 4.6
i don't have an ApplicationDidFinishLoading but I have this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES; }

Use Below Code instead in your ApplicationDidFinishLoading
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[YourFirstViewController alloc] initWithNibName:#"YourFirstViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
This may solve your problem. Please try it.

commenting the "shouldAutorotateToInterfaceOrientation" solved my problem.

Related

integerating twitter,facebook to iphone app using button is not working

I am trying to integrate Twitter and Facebook into my app.
I tried this demo, and it works only when I try it in a separate project. When I try it in my project it does not work (the actions do not integrate to the buttons).
It shows this message to me:
2013-06-25 11:50:39.885 app[1255:19703] Warning: Attempt to present <SLFacebookComposeViewController: 0xa199280> on <ViewController: 0x9497b60> whose view is not in the window hierarchy!
Refer this link:
stackoverflow
Quoted from the above link:
-(void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.blankviewController = [[blankPageViewController alloc] initWithNibName:#"blankPageViewController" bundle:nil];
self.window.rootViewController = self.blankviewController;
[self.window makeKeyAndVisible];
}

Multiple storyboard to manage the retina 4 and retina 3.5

Hi I'm trying to develop an app for iPhone 5 and iPhone 4/4s. I'm having trouble while using storyboard: I designed the storyboard for iPhone 4/4s, but when I try it on an iPhone 5 my GUI sucks...
I read on the internet that the easiest solution it's to use 2 storyboard: one for retina 4 and one for retina 3.5.
I wanted to ask you how I can call the different storyboard by code?
I created 2 storyboard file:
MainStoryboard.storyboard
MainStoryboardiPhone5.stroryboard
I found on internet that i should obtain the screen size of the device and load a different storyboard, but where I should do that? In Appdelegate.m in method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
To detect the size of the display I founded this code on the web:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (screenBounds.size.height == 568) {
NSLog(#"retina 4");
} else {
NSLog(#"retina 3.5");
}
return YES;
}
Now I should only find a way to invoke the different storyboard when I detect a retina 4 or a retina 3.5.
What I should do to invoke the correct storyboard?
Thank you
The iPhone 5's screen has a height of 568.
You can simply use this macro to check it its iPhone 5:
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < DBL_EPSILON)
Then in your AppDelegate.m check for iPhone 5 and load that particular storyboard.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *mainStoryboard = nil;
if (IS_IPHONE_5) {
mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboardiPhone5" bundle:nil];
}
else {
mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [mainStoryboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
UPDATE:
Using the following macro
// Check if device is iPhone 5
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < DBL_EPSILON)
// Get the storyboard name according to the device
#define GET_STORYBOARD_NAME(controllerName) IS_IPHONE_5 ? controllerName : [NSString stringWithFormat:#"%#-iPhone4",controllerName]
Now in your App Delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:GET_STORYBOARD_NAME(#"Main") bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
Note:
Always the iPhone4 storyboard name should be in this format
YourStoryboardName-iPhone4.storyboard
I know it's not really what you're asking, but it's really worth persevering with AutoLayout. Unless your views are so different (eg, using different graphics, etc), AutoLayout can cope with pretty much anything by way of rearranging stuff. It's tricky to start with as it doesn't really use static positions for your layout items, it works by you telling it your intentions for how to place things relative to everything else (superview, other items, etc). Check out some tutorials online (Ray Wenderlich's one is very good).

iPad simulator Interface rotation 90°

I am developing an app (a drum machine) for the iPad, I have a draft of the user interface.
The interface is OK in iOS 6.1 simulator:
But it's turned 90° in iOS 5.1 simulator:
This is how I call the View (after some help from stackoverflow members)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[XDrumViewController alloc] initWithNibName:#"XDrumViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
How to solve it?
It is likely that you are not defining
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
which is required on iOS < 6 to make autorotation work (see here). For a quick test, define:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
in your view controller. This will enable autorotation for landscape only (i.e, it will force your controller to landscape).

Restart application after low memory warning

I'm using my appDelegate's applicationDidReceiveMemoryWarning method to dump some high resource objects. When the app starts back up, rather than trying to reload just those objects and return the user to his last page, I would like just to restart the app from the top (from the main page, the app only goes one level deep, so this is totally acceptable to us).
Here's my paltry attempt, but it was an abject failure. It got close, but I ended up introducing some problems that resulted in an actual memory dump and app crash.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[SplashScreenViewController alloc] initWithNibName:#"SplashScreenViewController" bundle:nil];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navcon;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
//For testing purposes only
self.lowMemoryWarning = TRUE;
NSLog(#"app did enter background");
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(#"app will enter foreground");
if (self.lowMemoryWarning) {
NSLog(#"recovering from low memory warning");
self.window.rootViewController = nil;
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navcon;
[self.window makeKeyAndVisible];
}
}
What's the best approach for doing something like this? Is there maybe a simple trick that I don't know about?
Thank you!
Do you mean you want the app to restart each time it started (or enter foreground) ? If yes, maybe you can just set the app to not support multi tasking
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW5
Search for "Opting out of Background Execution"
================================================================================
Ah sorry, I didn't know the nature of your application, if some process need to be run on the background then this method is no go.
I read your comment above about the UIActivityIndicator + loading the certain objects back on the current view after app enter foreground. Maybe this thread can help you, Finding the current view when application enter foreground. IOS

how to do different coding for iphone and ipad in same .m file in universal app?

I have created app for iPhone. I have no of table views, image views, map views in my app. All data coming through web service. And I've given some static sizes for image and other views through coding. now, I need the same app for iPad. So i have to change coding of view sizes for Ipad. I need to do different coding for iPhone and iPad in the same .m file. Anyone pls suggest me how to do that!!!
Till i understood your question, i think this is what u need:
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
// place the iphone code
}
else
{
// place the ipad code
}
and you can refer to this post : http://iphonedevelopment.blogspot.in/2010/04/converting-iphone-apps-to-universal.html
As you can see when you choose a universal app in the starting when you are taking a new project - in universal app Appdelegate.m file the apple provides the code for that.
see this -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
by same method you can distinguish the iPad and iPhone.
Thank You!!