Basically as the title says, I am having some issues in my WebViewAppDelegate
https://github.com/austin4195/Nucleus-iOS/blob/master/Classes/WebViewAppDelegate.m
Lines 5-48, but I believe the issue is something with defining the item that will store the value
Thanks!
There are a lot of issues with your code:
You have return statement in line 36, so your code is never called.
screenshotTaken should be declared outside of application:didFinishLaunchingWithOptions:.
You should use self.webViewController.theWebView instead webViewController.webView.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
navigationController = [[UINavigationController alloc] init];
navigationController.navigationBar.hidden = YES;
navigationController.toolbar.barStyle = UIBarStyleBlack;
WebViewController *webViewController = [[WebViewController alloc] init];
webViewController.urlString = #"http://files.austinapps.org/File%20Site";
[navigationController pushViewController:webViewController animated:NO];
[webViewController release];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
self.webViewController = webViewController;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(screenshotTaken)
name:UIApplicationUserDidTakeScreenshotNotification
object:application];
return YES;
}
- (void)screenshotTaken{
[self.webViewController.theWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://website.com/"]]];
}
Related
Im modifying an older ios app which has the mainscreen setup through :
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [UITabBarController new];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];
How can i programatically redirect back to that screen? Im adding a login screen and need to know how to redirect after successful login.
Thanks
#define kUserAuthChangedNotification #"kUserAuthStatusChanged"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self changeRootControllerWithIsUserSignIn:NO];//You must send user sign in or not
[self.window makeKeyAndVisible];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(userAuthStatusChanged) name:kUserAuthChangedNotification object:nil];
}
#pragma mark helper methods
- (void)userAuthStatusChanged {
[self changeRootControllerWithIsUserSignIn:YES];//You must send user sign in or not
}
- (void)changeRootControllerWithIsUserSignIn:(BOOL)isSignIn {
if(isSignIn){
rootViewController = [UITabBarController new];
self.window.rootViewController = rootViewController;
[self setup];
} else {
YourLoginViewController * ctrl = [YourLoginViewController new];
self.window.rootViewController = ctrl;
}
}
When successful login Or log out you must call:
[[NSNotificationCenter defaultCenter] postNotificationName:kUserAuthChangedNotification object:nil];
I got an error in my console and crash.
“Application windows are expected to have a root view controller at the end of application launch”
Below is my piece of code, after enter the return YES line crash will happens.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIImageView *defaultImage = [[UIImageView alloc] initWithImage:splashImage];
defaultImage.frame = defaultImageFrame;
[self.window addSubview:defaultImage];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self
selector:#selector(login:)
userInfo:nil
repeats:NO];
[self.window setBackgroundColor:[UIColor clearColor]];
[self.window makeKeyAndVisible];
return YES; // here crash will happens
}
-(void)login:(id)sender
{
PreLoginViewController *appController = [[PreLoginViewController alloc] initWithNibName:nil bundle:nil];
if (_ChooseLogin.isStatus == 105)
{
flagRequired = #"1";
appController.serverDownFlag = #"1";
}
appController.termsURL = _ChooseLogin.urlString;
appController._ChooseLogin = _ChooseLogin;
appController.rootNetworkAvailable = NO;
appController.verionMsg = versionStr;
[dft setBool:NO forKey:#"isNeedActivate"];
appController.isNeedActivate = NO;
navigationController = [[UINavigationController alloc]
initWithRootViewController:appController];
}
Any one know how to fix this issue? its workes fine in iOS 8, upto Xcode 6.3.
You need to call setRootViewController: in your didFinishLaunchingWithOptions: and you need a view controller to do this.
In code:
UIViewController *vc = [[UIViewController alloc] init];
[vc.view addSubview:defaultImage];
[self.window setRootViewController:vc];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MainViewController *rootViewController = [[MainViewController alloc] init];
_naviControl = [[UINavigationController alloc]initWithRootViewController:rootViewController];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window addSubview:_naviControl.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
In my AppDelegate ..!
Connect to MainViewController.m
The AppDelegate is not a UIViewController so connecting a UITableView to it conflicts with the MVC principles as described here: https://developer.apple.com/library/ios/documentation/general/conceptual/devpedia-cocoacore/MVC.html
what you want to do is make your MainViewController's view have a tableView as a subview
something like this:
(in MainViewController.m)
- (void)viewDidLoad {
[super viewDidLoad];
self.feedTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.feedTableView.dataSource = self;
self.feedTableView.delegate = self;
[self.view addSubview:self.feedTableView];
}
Receiving this error.
2013-02-28 16:19:49.628 VLC[1416:907] Warning: Attempt to present on whose view is not in the window hierarchy!
This is my code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// This will mark crashy files
[[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
[_window addSubview:self.navigationController.view];
[_window setRootViewController:self.navigationController];
[_window makeKeyAndVisible];
NSURL * urlToOpen = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
urlToOpen = [NSURL URLWithString:#"rtsp://192.168.4.123"];
if (urlToOpen != nil) {
// We were started to open a given URL
MVLCMovieViewController * movieViewController = [[MVLCMovieViewController alloc] init];
movieViewController.url = urlToOpen;
[self.navigationController presentViewController:movieViewController animated:YES completion:NULL];
[movieViewController release];
}
return YES;
}
You haven't initialized your navigationController with UIViewController before adding to window.
Try it like:
YourViewController *object_yvc = [[YourViewController alloc] initWithNibName:#"YourViewController"
bundle:[NSBundle mainBundle]];
UINavigationController *navObject_vc = [[UINavigationController alloc] initWithRootViewController:object_yvc];
If I'll remove [self.window makeKeyAndVisible] , my code works. But I don't understand why do I need to remove makeKeyAndVisible?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.tabBarController;
if (isLoginScreenNeeded)
{
LoginModalViewController *controller = [[[LoginModalViewController alloc] initWithNibName:#"LoginModal" bundle:[NSBundle mainBundle]] autorelease];
UINavigationController *controllerNav = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
[self.window.rootViewController presentModalViewController:controllerNav animated:NO];
//[self.window makeKeyAndVisible]; //controllerNav didn't appeared if I uncomment this string
}
else
{
[self.window makeKeyAndVisible];
}
return YES;
}