ios - 在 Cordova 插件中将变量传递给 AppDelegate
问题描述
有什么方法可以让我在 AppDelegate 中获取偏好值?或者至少将变量从 CDVPlugin 子类传递给 AppDelegate?
我正在为 iOS 编写一个 Cordova 插件,其中有这 2 个 Objective-C 文件,第一个用于添加额外的委托事件,第二个是 CDVPlugin 子类。
我必须访问两个文件中的首选项值才能获取应用程序密钥。
// AppDelegate
@implementation AppDelegate (AppDelegate)
- (void) application:(UIApplication*)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
// I need access the app key here
}
- (void) application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// ...
}
- (void) application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
// ...
}
- (void) application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// I need access the app key here
}
@end
// CDVPlugin
@implementation MyPlugin
- (void) pluginInitialize
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishLaunchingNotification:) name:UIApplicationDidFinishLaunchingNotification object:nil];
}
- (void) didFinishLaunchingNotification:(NSNotification*)notification
{
// I need access the app key here
}
- (void) start:(CDVInvokedUrlCommand*)command
{
// ...
}
@end
因为 CDVPlugin 子类很简单,我可以访问保存值的设置字典:
[self.commandDelegate.settings objectForKey:[@"appkey" lowercaseString]];
但是,在 AppDelegate 中,我无权访问commandDelegate
或类似的东西。
所以,我的问题是:
有什么方法可以让我在 AppDelegate 中获取偏好值?或者至少将变量从 CDVPlugin 子类传递给 AppDelegate?
解决方案
推荐阅读
- java - Android (Java) - 通过电子邮件查找联系人并预览(如果存在)
- asp.net - asp.net Web 表单中的 Microsoft Graph 访问令牌过期 - 如何在 Web 表单应用程序而不是 MVC 中刷新令牌
- java - HttpClientErrorException.getStatusText 和 HttpClientErrorException.getResponseBodyAsString 之间的区别
- python - 如何在正确继续程序的同时终止循环?
- if-statement - 不尊重 if 语句
- ios - 断点调试器命令中的“po $arg1”和“bt”有区别吗?
- auto-keras - AutoKeras 中需要 final_fit 吗?
- vue.js - Vue 如何检查实例化?
- mongodb - 作为服务启动时出现未知错误的 Mongodb 错误
- node.js - 文档上的猫鼬模式数组属性不断变化