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
Related
I installed third party library using pods, which has it's own navigationController. I my existing project I am setting the rootViewController in the app delegate. I am pushViewController to the library ViewController (which is in it's own navigation stack). When I exit and then push to the library for a second time the ViewAlready seems to be there before transitioning the same view over the top.
In my appDelegate...
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
appbarViewController = [[AppBarViewController alloc] init];
[self loadNormalFlow];
[self.window makeKeyAndVisible];
}
- (void)loadNormalFlow
{
self.navigation = [[UINavigationController alloc]initWithRootViewController:appbarViewController];
self.window.rootViewController = self.navigation;
[self.navigation setNavigationBarHidden:YES];
}
-(void)displayLibraryView
{
ACSViewController *acs = [[ACSViewController alloc] init];
[self.navigation pushViewController:acs animated:nil];
}
Within library ViewController class to return back to original rootViewController i am using
[[UIApplication sharedApplication].delegate performSelector:#selector(loadNormalFlow)];
I seems like it is not properly dismissing the library ViewController, or it does a push twice? Any idea?
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 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];
I've got your standard table application built right now. Window has a UINavigationController as its rootViewController, and that UINavigationController was initialized with its rootViewController as my custom UITableController.
My applications table data changes over time. If I open my application up from a suspended state then my data is stale. How do I get applicationWillEnterForeground to update my data? I tried something awkward like
- (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];
HabitsTable* vc = [[HabitsTable alloc] init];
[vc initCoreData];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[[[self window] rootViewController] navigationController] rootViewController]
}
But, no surprise, that doesn't work. I'm not sure how to get at my UITableController?
I'd recommend using the NSNotificationCenter. You can see a nice example of how to use the class here.
I believe your close try:
UINavigationController *navController = (UINavigationController*)[[self window] rootViewController];
HabitsTable *tableView = (HabitsTable*)[navController topViewController];