appdelegate

Swift: How to access in AppDelegate variable from the View controller?

爷,独闯天下 提交于 2019-12-18 12:15:34
问题 I would like to write in the text or csv (prefer) file the variable from the view controller. Indeed I am doing a drawing app and I would like to write in the file the current position of the finger. class ViewController: UIViewController {var lastPoint = CGPoint.zeroPoint ... } I would like to have access to lastPoint.x and lastPoint.y from the AppDelegate. how I could do that ? Thank you. 回答1: Your question is full of confusion but if that's what you are looking for: You can access the

UIStatusBarStyle not working in Swift

二次信任 提交于 2019-12-18 09:58:13
问题 I'm trying to change the Status Bar color in my Swift app to white, but am hitting a brick wall. I have 3 ViewControllers that are each embedded in a NavigationController (could that be the issue? I've already tried to place the code in the NavigationController class.) I've tried both of the following pieces of code in the didFinishLaunchingWithOptions of my AppDelegate.swift file but neither worked. application.statusBarStyle = .LightContent and UIApplication.sharedApplication()

Change initial view controller after first launch of app

半城伤御伤魂 提交于 2019-12-18 09:34:51
问题 I have a two-view login to my app where a user enters two views worth of info. After the user has entered that info I want change which view is the initial view controller, and have the login view be a settings-like page. How can I change the initial view controller after the user has passed a certain point in the app? 回答1: For one of my apps, where I did similar to this, I have my "main" view controller check on viewDidLoad for a setting in the default settings that would indicate if the

Why is AppDelegate.swift window an optional?

末鹿安然 提交于 2019-12-18 03:31:53
问题 I was reading Apple docs, when I found this sentence: The AppDelegate class contains a single property: window . var window: UIWindow? This property stores a reference to the app’s window. This window represents the root of your app’s view hierarchy. It is where all of your app content is drawn. Note that the window property is an optional, which means it may have no value (be nil) at some point. What I don't understand is: why this property at some point could be nil? What's the case for it

Calling UIViewController method from app delegate [duplicate]

半城伤御伤魂 提交于 2019-12-17 15:36:18
问题 This question already has answers here : iOS - Calling App Delegate method from ViewController (12 answers) Closed 3 years ago . I know there are duplicates of this question but my situation is different here. When user goes back to the home (void)applicationDidEnterBackground gets invoked from the AppDelegate class. However once user presses home button, I don't want user to see this view controller again, so I have a method named (void)goToBeginning that switches to another view controller.

iOS Swift Navigate to certain ViewController programmatically from push notification

喜你入骨 提交于 2019-12-17 14:56:18
问题 I use push notifications to inform the user about different types of events happening in the app. A certain type of push notification should open a special viewcontroller (f.e a notification about a new chat message does navigate to the chat on click) To achieve this, i tried the following code inside my app delegate: func applicationDidBecomeActive(_ application: UIApplication) { if var topController = UIApplication.shared.keyWindow?.rootViewController { while let presentedViewController =

Open a view controller when a iOS push notification is received

◇◆丶佛笑我妖孽 提交于 2019-12-17 07:11:57
问题 I want to open a specific view controller when a user clicks on the received push notification message, but when I receive a push notification message and click the message, only the application opens, but it does not redirect to a specific view controller. My code is -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { if (applicationIsActive) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Bildirim" message:[NSString

Watchkit , openParentApplication with WatchKit Extension

孤街浪徒 提交于 2019-12-17 06:57:50
问题 First times doesn't work "Null" ( before open App in iPhone ) and some times doesn't work but i want one loop or timer for repeat this request for get result : here is my code - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply { // Temporary fix, I hope. // -------------------- __block UIBackgroundTaskIdentifier bogusWorkaroundTask; bogusWorkaroundTask = [[UIApplication sharedApplication]

didBecomeActive un-pauses game

▼魔方 西西 提交于 2019-12-13 21:12:38
问题 I am pausing my game with a willResignActive notification, and it seems to pause the game, but when didBecomeActive is called, it seems to un-pause on its own. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResign) name:UIApplicationWillResignActiveNotification object:NULL]; - (void) applicationWillResign { self.scene.view.paused = TRUE; NSLog(@"About to lose focus"); } How do I get it to stay paused? Do I actually need to pause it in my AppDelegate?

applicationWillEnterForeground present a view controller

本秂侑毒 提交于 2019-12-13 19:31:10
问题 I have a PIN view controller which needs to be presented every time the - (void)applicationWillEnterForeground:(UIApplication *)application fires. I have multiple view controllers and when the app enters background the user could be on any of them. The problem is I don't know how to present the PIN view controller over any view controller that is currently active. Here's how my implementation looks: - (void)applicationWillEnterForeground:(UIApplication *)application { ResourceSingleton