【发布时间】:2021-01-29 21:31:56
【问题描述】:
我创建了一个带有本机 sdk 的框架,我工作的公司用于推送通知。我在这个框架中有一个 Appdelegate,因为有一些文件使用它。我已将此框架添加为 Cordova 测试应用程序的插件,但正如我所见,我只能使用现在存在的两个 AppDelegate 之一(一个在框架中,一个在 cordova 应用程序中)。我试图只使用框架的 AppDelegate,但要做到这一点,我必须以某种方式使用 CDVAppDelegate。问题是初始化中的应用程序没有运行正确的didFinishLaunchingWithOptions 函数,我看不到cordova 应用程序的默认首页。我在插件里面有这个文件:
AppDelegateExtension.m
#import "xxxSDK/AppDelegate.h"
#import "xxxSDK/xxx.h"
#import "MainViewController.h"
#import "MyPlugin.h"
@implementation AppDelegate (MyPlugin)
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
#if (DEBUG == 1)
[xxx launchWithAppUUID:@"1256fbeb638b4426a98e4bacbc5f56f5" launchOptions:launchOptions];
#else
[xxx launchWithAppUUID:@"1256fbeb638b4426a98e4bacbc5f56f5" launchOptions:launchOptions];
#endif
[[xxx sharedService].pushManager registerForRemoteNotifications];
[[xxx sharedService].pushManager resetBadge];
MyPlugin.myPlugin.viewController = [[MainViewController alloc] init];
[MyPlugin.myPlugin application:application didFinishLaunchingWithOptions:launchOptions];
return YES;
}
MyPlugin.h
#import <Cordova/CDVAppDelegate.h>
@interface MyPlugin : CDVAppDelegate
// Public static method
+ (CDVAppDelegate*) myPlugin;
@end
MyPlugin.m:
#import <Foundation/Foundation.h>
#import "MyPlugin.h"
#import "MainViewController.h"
@implementation MyPlugin
// Private static reference
static CDVAppDelegate* myPlugin;
// Public static method
+ (CDVAppDelegate*) myPlugin {
return myPlugin;
}
@end
在框架内,AppDelegate.h 是这样的:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@end
我也尝试将 MyPlugin 声明为 CDVPlugin,但问题没有得到解决。有什么想法吗?
【问题讨论】:
标签: ios cordova cordova-plugins appdelegate ios-frameworks