I have not started any of facebook view or method in appDidFinishLoadingWithOptions: but stil when I start app at first, then stop and restart it, it hangs. If i press the pause button i can see the stack trace shown in image.
This code in method applicationDidBecomeActive was creating the issue. Anyone know what can be a possible reason. Removing this solved my issue.
- (void)applicationDidBecomeActive:(UIApplication *)application {
if (FBSession.activeSession.state == FBSessionStateCreatedOpening) {
[FBSession.activeSession close]; // so we close our session and start over
}
if (FBSession.activeSession.isOpen) {
}
}
Actually you have to navigate the page to another view controller so try this.
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
UIViewController *splashController = [[UIViewController alloc]init];
UINavigationController *detailednewscontroller=[[UINavigationController alloc]initWithRootViewController:splashController];
[self.window setRootViewController:detailednewscontroller];
[self.window makeKeyAndVisible];
return YES;
}
Related
I'm trying to display the webpage google.com using the following. For some reason it's not presenting the controller with google.com. Can anyone help?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
SFSafariViewController *vc = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:#"https://www.google.com"]];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:vc animated:YES completion:nil];
return YES;
}
I think this should work:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
SFSafariViewController *vc = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:#"https://www.google.com"]];
self.window.rootViewController = vc;
return YES;
}
try this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SFSafariViewController *vc = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:#"https://www.google.com"]];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
How to use SFSafariview controller first check on this link.
SFSafariViewController
Moreover you can check full tutorial in below link also,
Example 1 :- iOS-SafariViewControllerFinishedProject
Example 2 :- ios-9-getting-started-with-sfsafariviewcontroller
From github you can also download Demo Project. IOS9SafariViewControllerTutorial Example
Edit :-
I have make demo for you without storyboard. please check on below link.
Safari without storyboard demo
Output :-
Move the SafariViewController presentation code to viewDidAppear of your RootViewController. If your RootViewController is a UINavigationController, move it to the viewDidAppear of your Navigation Controller's topViewController
originally when i tried to test my app i was getting this
[2685:70b] Application windows are expected to have a root view
controller at the end of application launch
and so i changed ccAppDelegate.m
From this
#implementation ccAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
To this
#import "ccAppDelegate.h"
#import "ccViewController.h"
#implementation ccAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ... Other code
// Override point for customization after application launch.
UIViewController *viewController = [[UIViewController alloc] init];
self.window.rootViewController = viewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
now it is no longer crashing but nothing appears but a white screen
what can i do to fix this?
i have a copy of my work here if anyone wishes to have a look at all the code
https://drive.google.com/file/d/0B3_fSZXQB18lVzZuQVdpT3dnWjQ/edit?usp=sharing
as stated in the comments, you're creating and displaying an empty view controller as the root view controller. As result, you're seeing your brand new empty view controller.
If you want to use your view controller as the root one, you should change the line
UIViewController *viewController = [[UIViewController alloc] init];
to:
MyCustomViewController *viewController = [[MyCustomViewController alloc] init];
where obviously MyCustomViewController should be replaced with the name of your class ( I think it is ccViewController but I'm not sure)
Your method is good but to see anything onscreen you need to add anything rg. UIButton, UIImageView. I assume that you are doing everything in code so if this is hard for you why don't you try Storyboarding.
Anyway, just paste this code and you'll see a red background:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ... Other code
// Override point for customization after application launch.
UIViewController *viewController = [[UIViewController alloc] init];
self.window.rootViewController = viewController;
self.window.backgroundColor = [UIColor redColor];
[self.window makeKeyAndVisible];
return YES;
}
All I've changed in your code is [UIColor whiteColor] to [UIColor redColor].
Need help with a "Application windows are expected to have a root view controller at the end of application launch" warning in my console when running my app. It's a core data test I am working on. I am not getting the NSLog statements I am using for testing, only the previous message.
I created a new project from an Empty Application. My app delegate didFinish method code was generated to look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
I added a storyboard and set it as the Main Interface. Then added a UITableView to the storyboard. Created a UITableViewController by adding a file and set it as the UITableView's class in the identity inspector.
It seems to get rid of the warning I should set the rootViewController. How do I set my UITableViewController as the rootViewController if I did not instantiate it in the appDelegate.m file? Alternately, If I do instantiate it in the appDelegate.m like so
UITableViewController *tableViewController = [[UITableViewController alloc]init];
self.window.rootViewController = tableViewController;
how do I associate tableViewController with corresponding .h and .m files?
Using Xcode 5.0.1, deployment target 7.0
When you add a storyboard to your empty application, and set the property "Main Storyboard file base name" in your Info.plist as the name of your storyboard, then the application instantiates your "window" object and assigns an instance of your storyboard's "initialViewController" as the "rootViewController" property of your window object. So you don't see the warning :
"Application windows are expected to have a root view controller at the end of application launch" when you do :
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
This works fine.
However, in the code :
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]
//Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
If you were using storyboards, you have overridden default behaviour by creating a new window object, which no longer has the rootViewController provided by storyboard. In this case, you have to explicitly add a root view controller to your window object.
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"YourStoryboard" bundle:[NSBundle mainBundle]];
YourTableViewController* vc = (YourTableViewController*)[storyboard instantiateInitialViewController];
_window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
Hope this helps !!
In StoryBoard set the desired controller as initialViewController.
In AppDelegate.m
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
youRootViewControllerObject = [storyboard instantiateInitialViewController];
This way you can access YouRootViewController class.
I did a lot of research and finally found out the right way to do this
in appDelegate.m instead of
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
The code should simply be
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
See Sitepoint's helpful page for more detailed information
http://www.sitepoint.com/ios-application-development-storyboards/
I want to send a request to server when the app is selected in home screen, before the login screen is displayed.
Thanks in advance
there were no springboard icon tap method or home screen icon selection method for any app that you can detect but when your app icon is being tapped on spring board then at the time of launching your app below method called first so you can write your code for sending request to server there :-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I have an app, it authenticates with Instagram using safari, and when it returns I want it to load table view right away, without the login view.
Here is what I do now:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DVGViewController *myVC = [[DVGViewController alloc] initWithNibName:#"DVGViewController" bundle:nil];
self.viewController = [[UINavigationController alloc] initWithRootViewController:myVC];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// some code skipped
UITableViewController *myTVC = [[DVGTableViewController alloc] init];
self.viewController = [[UINavigationController alloc] initWithRootViewController:myTVC];
return YES;
}
At the moment I still get first method to work every time, although second method is triggered too, since I get calculations from url with it and I know that. Why it doesn't load tableView I don't know.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
method will call if you app is come fro m specific URl like from facebook auth or from safari then this method will call
I have found an error. In second method I have never set window and rootViewController. Adding this code to second method helped.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];