appdelegate

UINavigationBar setBackgroundImage in AppDelegate with Swift

无人久伴 提交于 2020-01-03 19:37:52
问题 I am trying to set a background image to the navigation bar globally in the App Delegate in Swift. I can get it to work on an individual View Controller like this: var topBar: UINavigationBar! topBar.setBackgroundImage(UIImage(named: "navbar"), forBarMetrics: .Default) But when I try and add the following to the App Delegate, it crashes with an uncaught exception: UINavigationBar.appearance().setBackgroundImage(UIImage(named: "navbar"), forBarMetrics: .Default) 回答1: OK, I deleted the

AppDelegate segue alternative pass data

为君一笑 提交于 2020-01-03 05:06:05
问题 I am struggling with passing data from my appDelegate to one of my view controllers. I have tried to use segues to do this, but this just doesn't work. So what I am wondering about is; is there any other way to present another view controller and pass data to it, other than using segues? Thanks in advance. 回答1: You can't use segue to ViewController from AppDelegate , because AppDelegate is not a ViewController . Segues are only work with ViewControllers . But you can initiate a storyboard

Swift send request to server when app killed [closed]

ⅰ亾dé卋堺 提交于 2020-01-03 04:53:39
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I want to make a request when the application enters the onBackground or onAppWillTerminate mode. I added an observer to AppDelegate method but did not work. Simply I want to send a request and push notification as a response. How can I do this? My request is not news or music, simple JSON. `func application(_

appdelegate shared instance delegate

天大地大妈咪最大 提交于 2020-01-02 07:29:12
问题 MyAppDelegate *appD; appD = [UIApplication sharedApplication]; if(appD.sw1.on) NSLog(@"It is ON"); else NSLog(@"It is OFF"); Gives no error while compiling. Runs without any warning, but it doesn't work. I dont see what the problem is. ... EDIT: OMG, should have called delegate method too: appD = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 回答1: I recommend you this method to share the app delegate: https://coderwall.com/p/z4h4uw?i=2&p=1&q=&t%5B%5D=%21%21mine&t%5B%5D=%21

iOS difference between AppDelegate and ViewController class [closed]

给你一囗甜甜゛ 提交于 2020-01-01 17:25:08
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . How do I know what code goes in the AppDelegate class and what code goes in the ViewController class. Both classes have a similar method of viewDidLoad in UIViewController and applicationDidFinishLaunching: in UIApplicationDelegate . I guess applicationDidFinishLaunching: would be

Facebook Login does not return to App with Xcode 7 iOS 9

左心房为你撑大大i 提交于 2020-01-01 10:57:10
问题 I have implemented this method for Facebook Login in the App Delegate using Xcode 7 and it works perfectly: - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options { return [[FBSDKApplicationDelegate sharedInstance] application:app openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]; } However, since I need to use Xcode 6 to submit my app to the

application openURL in Swift

◇◆丶佛笑我妖孽 提交于 2019-12-30 18:34:31
问题 I am having an issue with the Appdelegate method OpenURL. I have setup my Imported UTI's and Document Type. But when opening my app from a mail attachment, the app crashes immediately when I have the method implemented. The depreciated handleOpenURL works, but not OpenURL? At the moment I have no code in the implementation, and am just returning true. func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool { return true } The

game exits from pause state after resuming it from background in swift

一个人想着一个人 提交于 2019-12-30 07:29:10
问题 I'm developing a game with SpriteKit that can be paused during execution and can be resumed. But I have a problem with applicationDidEnterBackground when the home button is pressed while the game is paused because when I resume the game the entities start moving immediately even though the game was paused before. I cannot find a way to implement applicationDidEnterBackground and other related method in AppDelegate since there is no connection between that and my GameScene.swift I'm actually

How to detect all touches in Swift 2

橙三吉。 提交于 2019-12-30 06:44:07
问题 I'm trying to create a timeout function for an app I'm develop using Swift 2 but in swift 2, you can put this code in the app delegate and it works but it does not detect any keyboard presses, button presses, textfield presses, and etc: override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { super.touchesBegan(touches, withEvent: event); let allTouches = event!.allTouches(); if(allTouches?.count > 0) { let phase = (allTouches!.first as UITouch!).phase; if(phase ==

Get current view controller from the app delegate (modal is possible)

和自甴很熟 提交于 2019-12-28 12:08:28
问题 I know that to get the current view controller from the app delegate, I can use the navigationController property I have set up for my app. However, it's possible in many places throughout my app that a modal navigation controller could have been presented. Is there any way to detect this from the app delegate, since the current navigation controller will be different from the one to which the app delegate holds a reference? 回答1: I suggest you use NSNofiticationCenter. //in AppDelegate: