这是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)
如果任何程序员想要了解更多代码或要求,欢迎通过编辑我的代码或注释来提供.
这是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) 我是以编程方式实现列表视图控制器.当我尝试运行该项目时,我收到错误:
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
如果我覆盖
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)
在前台发送应用程序通知时,我没有调用该方法.为什么第一个工作,但第二个不适用于应用程序在前台?
请注意,我一次只实现其中一个.不是两个在同一时间.
任何人都可以帮我实现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
我知道这个问题有重复,但我的情况在这里有所不同.
当用户返回主页(void)applicationDidEnterBackground时,从AppDelegate类中调用.但是一旦用户按下主页按钮,我不希望用户再次看到这个视图控制器,所以我有一个名为(void)goToBeginning切换到另一个视图控制器的方法.我希望能够从AppDelegate调用此方法.我真的不想用NotificationCenter它.此处选择的解决方案:
从app委托调用视图控制器方法
对我来说不起作用,因为它初始化新对象,而我希望能够调用已在视图中的对象.我怎样才能做到这一点?我使用的是iOS 7和XCode 5.
我试图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) 我有一个自定义URL方案,ViewController当我转到此URL时,我想打开一个不是根的某个.我已经能够做到这一点,剩下的是推动这一ViewController进navigationController从AppDelegate那里我处理我的网址是这样的:
- (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我想要启动.知道我怎么能以不同的方式做到这一点?
我最近更新了我的firebase消息传递盒,并按照Firebase的快速入门指南执行必要的升级更改.
我添加了新的extension AppDelegate : MessagingDelegate扩展程序,但遇到了一些错误.
appdelegate ×10
ios ×9
objective-c ×3
swift ×2
uiwindow ×2
iphone ×1
rootview ×1
swift3 ×1
swiftui ×1