FAQ Database Discussion Community


Accessing a parent UIViewController from its children UIViewControllers

ios,swift,uiviewcontroller,appdelegate
I have a UIViewController called Container, that houses two other child UIViewControllers: Master and Detail. My problem is trying to access the Container from one of its child controllers. App Delegate Code: @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var container: Container? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:...

Navigating beetween two viewController

ios,swift,uiviewcontroller,appdelegate
I have set my initial ViewController as rootViewController in appDelegate because I don't use storyboard. It looks like this way: var window: UIWindow? var mainNavigationController: UINavigationController? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { self.mainNavigationController = UINavigationController() var mainController: UIViewController? = TineLineViewController() self.mainNavigationController!.pushViewController(mainController!, animated: true)...

What's the equivalent of app delegate file for apple watch app?

appdelegate,watchkit,apple-watch
I want to set the initial view controller for the watch app base on different type of notification received on the watch. But I don't know where's to set it. This is the answer for an iOS app Multiple entry points to a storyboard...

Swift - Accessing AppDelegate window from viewController

ios,swift,uiviewcontroller,appdelegate
I make walkthrough (onboarding flow) in my app and I'd like to have a skip button. The button is located on viewController, so I figured out that the best way to move to another viewController would be access app delegate window. However, it keeps getting me an error that AppDelegate.Type...

Referring to NSPersistentStore instances created in AppDelegate

ios,swift,core-data,appdelegate,nspersistentstore
I modified the boilerplate core data stack code you get with a core data application to add two NSPersistentStores to the NSPersistentStoreCoordinator instead of just one. // MARK: - Core Data stack lazy var applicationDocumentsDirectory: NSURL = { let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) return urls[urls.count-1] as NSURL }() lazy...

Swift Code in App Delegate to Load Storyboard Causes Crash

ios,swift,appdelegate,xcode-storyboard
I have an universal app I am writing and I initially wrote it using two storyboard files. I had code in the App Delegate didFinishLaunchingWithOptions routine to decide which storyboard to load and away it would go. I have since realised that that was a silly thing to do because...

ios Objective C delegate methods

ios,objective-c,sdk,appdelegate
This is my first day of Objective C so I apologise for the lack of knowledge. I need to import an existing SKD into an App and I done it successfully. Now I need to create the delegate methods and I don't understand how can I do it. This is...

Why is my window smaller than the device viewport?

ios,swift,appdelegate,uiwindow
So I've started my endeavour to learn swift, and I thought I'd start by making a new app. It's based on a Tabbar controller with 2 view controllers. I also greatly dislike storyboards and nibs, so I've removed all of the storyboards and references to them (I normally do this...

Load a controller embed to a UINavigationController from AppDelegate in Swift

ios,uitableview,swift,uinavigationcontroller,appdelegate
I need to display from AppDelegate a table view embed to an UINavigationController. Normally I use let viewController: UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("prova") as ViewController window?.rootViewController?.presentViewController(viewController, animated: false, completion: nil) but it doesn't work with embed controller, how need to be adapted this code? Here is a test project....

iOS tabBarController detect selected index in AppDelegate

ios,objective-c,uitabbarcontroller,uitabbar,appdelegate
AppDelegate.h ***** @interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate,UITabBarDelegate> AppDelegate.m ***** - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { NSLog(@"%lu",(unsigned long)tabBarController.selectedIndex); } This method not work any idea ? I want to scroll top when click tab bar item Help please :)...

Replace AppDelegate.h and AppDelegate.m to AppDelegate.swift

ios,xcode,swift,appdelegate,objective
I just have a Objective-C project and I want to use AppDelegate to access to my xcdatamodel, but when I add AppDelegate.swift to my project it show me a compile problem, it is error because it doesn't know what AppDelegate use and what is the main. Then I tried to...

How to use a variable in other class that is defined in AppDelegate

ios,swift,appdelegate
I have a variable var window: UIWindow? in AppDelegate.swift file inside class AppDelegate that I want to use in other class xyz.swift file inside class xyz as explained in here Get current view controller from the app delegate (modal is possible) but I am getting error at the first line...

Calling NSObject class method from the app delegate

ios,objective-c,appdelegate
I am trying to call a method from a NSObject class from my AppDelegate. Usually this works if calling from a UIViewController but not having luck within the AppDelegate. My code: AppDelegate.m #import "ACManager.h" @implementation AppDelegate { ACManager *acManager; } -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [acManager login]; } ACManager.h @interface...

Calling a class method into appDelegate gives funky notation

objective-c,ios8,sprite-kit,appdelegate
So I got this code inside the update() function/method that tracks the game session in seconds (this is for achievement purposes) If someone has a better way of doing this, I'm all ears: -(void)update:(NSTimeInterval)currentTime { if (pauseTimer == NO) { millisecondsTimer++; if(millisecondsTimer == 60) //Remember that SK runs at 60...

How do I use my class in AppDelegate.swift

ios,swift,appdelegate
I have a ‘Member' class inside the project and I'm trying to pass some data from Phone to Watch extension. The error says: Use of unresolved identifier ‘Member' I tried to create a module ‘MemberKit’ and import it but I still get this eror. Thanks in advance! func application(application: UIApplication,...

Why is didReceiveRemoteNotification not called but didReceiveRemoteNotification:fetchCompletionHandler called when my app is in the foreground?

ios,swift,apple-push-notifications,appdelegate
If I override override func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { println("hey) } I successfully have the method called with the app in the foreground when I send a push notification. If I override override func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])...

Understanding UITabBarController subclass initializer code in Obj- C

ios,objective-c,swift,appdelegate
I found a project on GitHub and am trying to implement it in my Swift project. I am stuck on the syntax of the following line: YALFoldingTabBarController *tabBarController = (YALFoldingTabBarController *) self.window.rootViewController; I cannot figure out how to initialize this line in the AppDelegate. Any help and explanation into what...

How to block landscape position from code, separetly for each view controller?

ios,swift,appdelegate,landscape-portrait
I know that I can select available orientation of my app in targets menu, but I would like to block landscape orientation for each screen EXCEPT the one with youtube player. I suppose this couldn't be done via app delegate since it does not distinct controllers and apply the rule...

UITextField customization in AppDelegate not working for Swift

ios,swift,uitextfield,appdelegate
I want to customise all the textFields at once via AppDelegate , I had tested the customisation working on individual ViewControllers but when I add the customisation through AppDelegate then it does not appears. Please guide me for what have I missed : func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)...

How to get App delegate to display a specific UIViewController after PushNotification

uiviewcontroller,notifications,local,appdelegate
I have a TabBarController as the App entry point. After a receiving Local-Notification, I want to display a specific UIViewController. Depending on the actual App-state (frontmost / not-frontmost, not running), I am able to catch the push notification by e.g. application:willFinishLaunchingWithOptions: or application:didReceiveLocalNotification: in the appdelegate. However, I am not...

Get currentViewController of View Controller in UITabBarController in UINavigation Controller

ios,objective-c,uinavigationcontroller,uitabbarcontroller,appdelegate
I would like to know how I can find the current view controller if I have a UITabBarController and within that TabBarController I have 4 different UINavigationControllers and then that NavigationController obviously has the stack of view controllers. In my app delegate I am trying to find out this information...

Background task stopping when device locked?

ios,nstimer,appdelegate,ios8.3
I have a timer running when the device enters the background as I want to keep a check on a small amount of data in my service. I am using the following code in the applicationDidEnterBackground method in app delegate UIApplication *app = [UIApplication sharedApplication]; //create new uiBackgroundTask __block UIBackgroundTaskIdentifier...

Getting information from a View Controller to AppDelegate

ios,swift,appdelegate
The scenario is as follows: I have a view controller that analyses input sounds. Once a sound is recognised, I set a local notification like so. var notification: UILocalNotification = UILocalNotification() notification.fireDate = NSDate(timeIntervalSinceNow: 0.0) notification.alertTitle = knn as String UIApplication.sharedApplication().scheduleLocalNotification(notification) This calls the application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) function...

Using the boolean value from appdelgate all across app

ios,boolean,appdelegate
In my app I need to check whether a user already exists or not and need to update accordingly. In order to achieve this I have created a boolean in appdelegate.h and accessed it all across the app. I need to do @property(strong,nonatomic)AppDelegate*appDelegate; appDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate] in view did...

how to get appDelegate with Urban AirShip (Swift)

ios,swift,appdelegate,urbanairship.com
After integrating Urban Airship, when I call let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate I always get nil. When I tried to get class of UIApplication.sharedApplication().delegate, it tells me, that it is UAAppDelegateProxy now. But let appDelegate = UIApplication.sharedApplication().delegate as? UAAppDelegateProxy also returns nil. How can I get my appDelegate? Edit...

application:openURL: method not being called

ios,objective-c,appdelegate
![enter image description here][1]I am using url schemes in my iOS application, but my: -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { is not being called. I've set up URL types in my info.plist and added both a URL identifier and URL schemes. Any ideas why this is not getting...

How to use int of app delegate in other class in IOS?

ios,objective-c,int,appdelegate
Can someone help me in answer below 3 question? It will help me to solve my problem. How to declare int in app delegate. How to transfer this int value to other class. How to NSLog this value in other class. ...

AppDelegate issues

ios,swift,appdelegate
I'm working on my first project on Swift. I'm new to iOS itself. I create various screens like register, sign in etc. using storyboard. The Register screen is linked from the Sign In screen. But the app crashes as soon as I tap on 'Register' link in the Sign In...

Referencing TabbarController created from StoryBoard in AppDelegate?

ios,swift,uitabbarcontroller,appdelegate
I have a tabbar app with an initial login screen. The tabbarController is set as the initial view in Storyboard with 1 VC that has a navigationController also embed. I have a loginVC instantiated and set as rootViewController in my AppDelegate. After the user has successfully sign in from the...

Opening view controller from app delegate using swift

ios,swift,uiviewcontroller,appdelegate
I am trying to create a push notification which determines which view to open according to information obtained from the push. I have managed to get the information from the push, but I am now struggling to get the view to get the view to open Looking at other stack...

EXC_BREAKPOINT when using self.window?.makeKeyAndView()

ios,swift,appdelegate
For some reason when I use self.window?.makeKeyAndView() in my AppDelegate, I get the EXC_Breakpoint. When I let the ViewController load in normally via Segue, it doesn't happen. Basically, my goal with this code is to skip the initial view controller if the user is already logged in. AppDelegate.swift: func application(application:...

Class Accessibility Throughout Project

ios,appdelegate
When I first began working on a long iOS project, my first, I had need for a small class that was readily accessible throughout the project. At first I passed it around as a property and it became way too much of a headache. So, even though I've seen posts...

Controller in Appdelegate is never released

ios,objective-c,appdelegate,strong-typing
I have a strong reference in my AppDelegate and when I pop controller it isn't being released. @property (nonatomic, strong) MenuViewController *menuViewController; This controller is not being decollated at all because I nslog dealloc and it isn't appearing. Is there a way around this without putting this property somewhere else?...

Detect deletion of Core Data

ios,swift,core-data,appdelegate
Extra info: I have a messaging view in which I have a UITextView of which I save the text in the conversation's variable draft in the viewWillDisappear. When the app tries to refresh the user's access code, they might get a "could not refresh" response, and the app logs the...

How To Make Last Visited Viewcontroller The RootViewController?

objective-c,uiviewcontroller,nsuserdefaults,uistoryboard,appdelegate
I figured it out. Thanks shim for the info!: UIViewController* vc = (UIViewController*)[[UIStoryboard storyboardWithName:@"iPhone4" bundle:nil] instantiateViewControllerWithIdentifier:@"MyViewControllerIdentifier"]; if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"currentViewController"] isEqualToString:@"iPhone4Level1"]) { [self.window setRootViewController: vc]; } ...

Call app delegate method from view controller

ios,swift,appdelegate
I want to know if I can call an app delegate method from another ViewController. When the app starts, the application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool i method is called. Can I call this method a second time from another view controller?...

Swift – Instantiating a navigation controller without storyboards in App Delegate

ios,objective-c,swift,uinavigationcontroller,appdelegate
I'm rebuilding an app without storyboards and the part of it that I'm having the most trouble with is navigating view-to-view programatically. Few things are written out there which don't use storyboards, so finding an answer for this has been tough. My problem is pretty simple. I have my ViewController...

Present a view controller from appdelegate

ios,objective-c,appdelegate
I am not using LaunchScreen.xib . I am using storyboard for splashscreen. I am calling an API to get the splash image . I am doing this in app delegate. I am able to display the image on my view controller,but I couldnt able to go to another controller once...

Stop async operations on window close

swift,cocoa,appdelegate
In my app delegate I have put the callback to stop the program when the window is shut. func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool { return true } This doesn't work however because (I assume) there is an async bluetooth task running. What is the best way to stop everything running...

Avoid duplicate execution of code in App Delegate

ios,objective-c,push-notification,appdelegate
I have a piece of code in my App Delegate which notifies my first View Controller that the user wants to be shown something straight away: - (void)notifyAppWithURL:(NSURL *)url { if(!url){ return; } NSDictionary *dict = [self parseQueryString:[url query]]; NSString *host = [url host]; [self notifyApp:host value:dict[@"id"]]; } - (void)notifyApp:(NSString...

iOS AppDelegate add supportedInterfaceOrientationsForWindow

ios,objective-c,xcode,appdelegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { NSUInteger orientations = UIInterfaceOrientationMaskPortrait; if (self.fullScreenVideoIsPlaying == YES) { return UIInterfaceOrientationMaskAllButUpsideDown; } else { if(self.window.rootViewController) { UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject]; orientations = [presentedViewController supportedInterfaceOrientations]; } return...

Run didFinshLaunchingWithOptions in the AppDelegate while application is running?

ios,objective-c,xcode,xcode6,appdelegate
Is there a way i can execute the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method while the app is running from a different ViewController?...

iOS - When to load JSON data

ios,json,xcode,appdelegate
I know this may sound general but wanted to get feedback/opinions on when or where to parse and store all the JSON data you will need for your view controllers. I want to use the AppDelegate didFinishLoadingWithOptions to instantiate a parent class that would grab the JSON data and store...

Call class method with argument from another class method in Swift

ios,swift,appdelegate,class-method,method-call
In my code file MyItemVC.swift I have defined the following class and method: class MyItemVC: UIViewController, UITextViewDelegate { var timer = NSTimer() func cycleTimer(toggleOn: Bool) { if toggleOn == true { // Timer calls the replaceItem method every 3 seconds timer = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: Selector("replaceItem"), userInfo: nil, repeats:...

Swift: Can't set StatusBarStyleLightContent

ios,swift,appdelegate,uistatusbar
This is really weird, I have page view controller with onboarding flow and I cannot set the white color in status bar. I added "Status bar style" with "UIStatusBarStyleLightContent" value in info.plist along with appropriate line in AppDelegate UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent Despite making these two steps I keep getting black...