appdelegate

Controlling which view controller loads after receiving a push notification in SWIFT

孤者浪人 提交于 2019-11-28 16:23:35
Once I receive a push notification and swipe to open it, it just opens my app and not the VC I want. So my question is how do I load the VC I want? I know if the app is open I would move the VC over to another inside the didReceiveRemoteNotification but how do I do it if the app isn't open? or if it is in background mode? Also I have TWO different push notifications, so therefore I need it to move ONE of TWO different VCs. How can I tell the difference between different push notifactions? Thanks. Updated for Swift 4.2 Like it was said, you want to register to remote notifications in

How to programmatically add a UITabBarController & UINavigationController in AppDelegate?

被刻印的时光 ゝ 提交于 2019-11-28 14:50:23
How to add a UINavigationController & UITabBarController programmatically in app delegate. Don't forget in the AppDelegate.h file to add: @property (strong, nonatomic) UITabBarController *tabBarController; Below is the AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.tabBarController = [[UITabBarController alloc] init]; ViewController1 *VC1 = [[ViewController1 alloc] init]; VC1.title = @"Tab Title Here"; UINavigationController *VC1Navigation = [

How to run timer thought the app entered background or is terminated

左心房为你撑大大i 提交于 2019-11-28 14:46:10
In my app I have a NSTimer, and a selector - (void)TimerCount . I also have a integer int CountNum , and every 0.01 second, it increases by 1 ( CountNum = CountNum + 1 ). Timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(TimerCount) userInfo:nil repeats:YES]; And I want the timer to resume thought the app is terminated or it entered background. How can I do this? If your application is terminated , you will not be able to continue processing. To operate in the background, there are such things as background tasks, but it sounds like your use case does not

Swift - AVAudioPlayer, sound doesn't play correctly

﹥>﹥吖頭↗ 提交于 2019-11-28 12:54:33
Because UILocalNotification is not being displayed while the application is in active stat, I'm trying to configure an UIAlertController and playing a little sound when it appears. I've no problem, in the AppDelegate , to handle the notification/create the alert. My problem concerns the sound. Indeed, it doesn't play correctly. Here is what I have so far : //... class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for

Spritekit - Keep the game paused when didBecomeActive

自作多情 提交于 2019-11-28 06:33:31
问题 I have a pause system with a function and a button and it works perfect, i know when the app enters background it automatically pauses and when it comes back it automatically unpauses itself, my problem is that I don't know how to keep it paused when it becomes active again. func applicationWillResignActive(application: UIApplication) { NSNotificationCenter.defaultCenter().postNotificationName("Pause", object: nil) // tried here } func applicationDidBecomeActive(application: UIApplication) {

swift ios - How to run function in ViewController from AppDelegate

回眸只為那壹抹淺笑 提交于 2019-11-28 04:59:43
问题 I am trying to run a function in certain ViewController using AppDelegate func applicationDidBecomeActive(_ application: UIApplication) { ViewController().grabData() } But somehow the function does not seem to run at all when the app has become active after entering the app from the background. The function looks like this func grabData() { self._DATASERVICE_GET_STATS(completion: { (int) -> () in if int == 0 { print("Nothing") } else { print(int) for (_, data) in self.userDataArray.enumerated

Swift – Instantiating a navigation controller without storyboards in App Delegate

二次信任 提交于 2019-11-28 04:32:51
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 and my SecondViewController and I want to push from the former to the latter. In AppDelegate : func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. window =

Opening ViewController In AppDelegate While Keeping Tabbar

喜你入骨 提交于 2019-11-28 01:38:20
In my Xcode project when a user taps on a notification I want to first send them to a certain item in my tabBar then I want to instantiate a view controller and send an object over to that view controller. I have code the that sends them to the tabBar I want, but I do not know how to instantiate them to the view controller while keeping the tabBar and navigation bar connected to the view controller. All the answers on this require you to change the root view controller and that makes me lose connection to my tabBar and navigation bar when the view controller is called. A Real Life Example of

Present UIAlertController from AppDelegate [duplicate]

女生的网名这么多〃 提交于 2019-11-27 14:17:00
This question already has an answer here: How to present UIAlertController when not in a view controller? 31 answers I'm trying to present a UIAlertController from the AppDelegate in my iOS app. Below is the alert and the present method. UIAlertController *alert = [UIAlertController alertControllerWithTitle:cTitle message:cMessage preferredStyle:UIAlertControllerStyleAlert]; //Configure alert and actions [self.window.rootViewController presentViewController:alert animated:TRUE completion:nil]; However, when I try to present the alert, it doesn't appear and I get the following alert in the

Get Instance Of ViewController From AppDelegate In Swift

懵懂的女人 提交于 2019-11-27 13:36:10
I am trying to load a specific ViewController from the app delegate in swift when a user clicks a UILocalNotification. I have figured out that this is called in this function: func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!) But when I try and access one of the open ViewControllers I think it's returning null because my application is crashing. Here is what I am trying: var rootViewController = self.window!.rootViewController var storyBoard = rootViewController.storyboard var setViewController = storyBoard