标签: appdelegate

如何在AppDelegate中更改其他ViewController中的RootViewController?

这是AppDelegate中的didFinishLaunchingWithOptions方法.让我解释一下场景,我在我的应用程序中开发了像facebook这样的sideMenu,但现在我必须根据屏幕更改sideMenu列表(ViewController)

这里的侧面菜单是SideMenuViewController,它是contains中的一个参数,最终成为window的rootViewController.

那么,最基本的问题是"如何更改成为windows的rootViewController的控制器或变量"

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

SideMenuViewController *leftMenuViewController = [[SideMenuViewController alloc] init];

self.container = [ContainerOfSideMenuByVeerViewController
                  containerWithCenterViewController:[self navigationController]
                  leftMenuViewController:leftMenuViewController];

self.window.rootViewController = self.container;

[self.window makeKeyAndVisible];

return YES;

}
Run Code Online (Sandbox Code Playgroud)

如果任何程序员想要了解更多代码或要求,欢迎通过编辑我的代码或注释来提供.

ios rootview appdelegate

14
推荐指数
3
解决办法
3万
查看次数

每当打开应用程序时,SwiftUI AppDelegate 都不会运行

这是AppDelegate我做的一个简单的:

import SwiftUI

class AppDelegate: UIResponder, UIApplicationDelegate {

    private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        print("application")
        // first launch
        // this method is called only on first launch when app was closed / killed
        return true
    }

    private func applicationWillEnterForeground(application: UIApplication) -> Bool{
        print("applicationWillEnterForeground")
        // app will enter in foreground
        // this method is called on first launch when app was closed / killed and every time app is reopened or change status from background …
Run Code Online (Sandbox Code Playgroud)

appdelegate swiftui

14
推荐指数
1
解决办法
5449
查看次数

如果想要使用主故事板文件,则app委托必须实现window属性

我是以编程方式实现列表视图控制器.当我尝试运行该项目时,我收到错误:

2012-11-07 22:46:34.719 myTableViewControl[12021:c07] The app delegate must implement the         window property if it wants to use a main storyboard file.
2012-11-07 22:46:34.722 myTableViewControl[12021:c07] -[AppDelegate setWindow:]:     unrecognized selector sent to instance 0x7674e70
2012-11-07 22:46:34.723 myTableViewControl[12021:c07] *** Terminating app due to uncaught     exception 'NSInvalidArgumentException', reason: '-[AppDelegate setWindow:]: unrecognized     selector sent to instance 0x7674e70'
*** First throw call stack:
(0x1c8e012 0x10cbe7e 0x1d194bd 0x10df7ea 0x1c7dcf9 0x1c7d94e 0x1d60 0x107b7 0x10da7     0x11fab 0x23315 0x2424b 0x15cf8 0x1be9df9 0x1be9ad0 0x1c03bf5 0x1c03962 0x1c34bb6 0x1c33f44     0x1c33e1b 0x117da 0x1365c 0x1bd2 …
Run Code Online (Sandbox Code Playgroud)

uiviewcontroller uinavigationcontroller uiwindow ios appdelegate

13
推荐指数
1
解决办法
2万
查看次数

为什么didReceiveRemoteNotification没有被调用但是didReceiveRemoteNotification:当我的应用程序在前台时调用fetchCompletionHandler?

如果我覆盖

override func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
    println("hey)
}
Run Code Online (Sandbox Code Playgroud)

当我发送推送通知时,我成功地使用应用程序在前台调用了该方法.

如果我覆盖

override func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    println("hey")
}
Run Code Online (Sandbox Code Playgroud)

在前台发送应用程序通知时,我没有调用该方法.为什么第一个工作,但第二个不适用于应用程序在前台?

请注意,我一次只实现其中一个.不是两个在同一时间.

apple-push-notifications ios appdelegate swift

13
推荐指数
1
解决办法
1万
查看次数

为什么AppDelegate.swift窗口是可选的?

当我发现这句话时,我正在阅读Apple文档:

AppDelegate类仅包含一个属性:window.

var window: UIWindow?

此属性存储对应用程序窗口的引用.此窗口表示应用程序视图层次结构的根.它是您绘制所有应用内容的地方.请注意,window属性是 可选的,这意味着它在某些时候可能没有值(为零).

我不明白的是:为什么这个属性在某些时候可能是零?是什么情况(来)是零?

uiwindow ios appdelegate swift

13
推荐指数
2
解决办法
2107
查看次数

如何实现iOS 10的推送通知[目标C]?

任何人都可以帮我实现iOS 10的推送通知,因为我已经实现了以下代码,但仍然遇到问题:

#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0"))
{
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
        if(!error){
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
    }];
}
else {
    // Code for old versions
}
Run Code Online (Sandbox Code Playgroud)

我收到错误提示

未知的接收器UIUserNotificationCenter

先感谢您!

objective-c push-notification ios nsusernotification appdelegate

13
推荐指数
2
解决办法
6378
查看次数

从app delegate调用UIViewController方法

我知道这个问题有重复,但我的情况在这里有所不同.

当用户返回主页(void)applicationDidEnterBackground时,从AppDelegate类中调用.但是一旦用户按下主页按钮,我不希望用户再次看到这个视图控制器,所以我有一个名为(void)goToBeginning切换到另一个视图控制器的方法.我希望能够从AppDelegate调用此方法.我真的不想用NotificationCenter它.此处选择的解决方案: 从app委托调用视图控制器方法 对我来说不起作用,因为它初始化新对象,而我希望能够调用已在视图中的对象.我怎样才能做到这一点?我使用的是iOS 7和XCode 5.

objective-c uiviewcontroller ios appdelegate

12
推荐指数
1
解决办法
2万
查看次数

从AppDelegate调用方法 - Objective-C

我试图ViewController.m从方法AppDelegate.m内部 调用my的现有方法applicationDidEnterBackground,所以我找到了这个链接:从app delegate调用UIViewController方法,它告诉我实现这段代码:

在我的ViewController.m中

-(void)viewDidLoad
{
    [super viewDidLoad];

    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    appDelegate.myViewController = self;
}
Run Code Online (Sandbox Code Playgroud)

在我的AppDelegate中:

@class MyViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (weak, nonatomic) MyViewController *myViewController;

@end
Run Code Online (Sandbox Code Playgroud)

在AppDelegate的实现中:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [self.myViewController method];
}
Run Code Online (Sandbox Code Playgroud)

所以我把这个代码放在我的项目中,它工作得很好,但我不明白代码如何工作,一行一行.怎么sharedApplication办?为什么我必须设置一个委托而不是只创建一个ViewController实例,如:

ViewController * instance = [[ViewController alloc] init];
[instance method];
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiviewcontroller ios appdelegate

12
推荐指数
2
解决办法
1万
查看次数

从AppDelegate启动ViewController

我有一个自定义URL方案,ViewController当我转到此URL时,我想打开一个不是根的某个.我已经能够做到这一点,剩下的是推动这一ViewControllernavigationControllerAppDelegate那里我处理我的网址是这样的:

- (BOOL)application:(UIApplication *)application
     openURL:(NSURL *)url
     sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {

if ([[url scheme] isEqualToString:@"njoftime"]) {

    NSDictionary *getListingResponse = [[NSDictionary alloc]init];
    getListingResponse = [Utils getListing:[url query]];;

    if ([[getListingResponse objectForKey:@"status"] isEqualToString:@"success"]) {
         ListingViewController *listingView = [[ListingViewController alloc]init];
         [self.window.rootViewController.navigationController pushViewController:listingView animated:YES];
         return YES;
    }
Run Code Online (Sandbox Code Playgroud)

但它只启动我的应用程序,而不是ListingViewController我想要启动.知道我怎么能以不同的方式做到这一点?

uiviewcontroller ios appdelegate

12
推荐指数
2
解决办法
2万
查看次数

Firebase消息传递中的"错误:使用未声明的类型MessagingDelegate"

我最近更新了我的firebase消息传递盒,并按照Firebase的快速入门指南执行必要的升级更改.

我添加了新的extension AppDelegate : MessagingDelegate扩展程序,但遇到了一些错误.

在此输入图像描述

ios appdelegate swift3 firebase-notifications

12
推荐指数
3
解决办法
4586
查看次数