如何解决如何解决.../AppDelegate.h:13:1:“AppDelegate”类的接口定义重复错误
我正在按照以下说明将 Appslflyer 集成到我的 React-Native 应用程序中:https://support.appsflyer.com/hc/en-us/articles/360017822178#testing-ios-uninstalls
我想达到什么目的
我需要跟踪 iOS 卸载。他们使用静默推送通知,并要求我从上面的链接中复制粘贴一些代码。
我的问题是什么?
我已经完成了所有其他工作来设置 p12 证书并安装,但我一直无法将说明中的代码与我的应用程序中的现有代码合并。
我尝试了什么?
我不知道我在看什么代码,但我尝试重命名 AppDelegate 以解决 .h 文件中重复的接口名称错误并将其导入为 AppDelegate2 但之后我不知道如何实现接口。
我还努力将一些代码粘贴到现有实现中,但仍然无法构建,而且即使成功构建,我也不知道它是否有效。
具有 Objective-C 专业知识的人可以提供帮助吗?提前致谢。
我在代码片段中留下了 AppDelegate 的完整内容,以防您发现我可以粘贴新代码的位置,让生活更轻松。
在我按照说明操作之前,我的 AppDelegate.h 看起来像这样:
#import <Foundation/Foundation.h>
#import <EXUpdates/EXUpdatesAppController.h>
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <UMCore/UMAppDelegateWrapper.h>
#import <AppsFlyerLib/AppsFlyerLib.h>
@interface AppDelegate : UMAppDelegateWrapper <RCTBridgeDelegate,EXUpdatesAppControllerDelegate>
@end
在我按照说明操作后,它看起来像:
#import <Foundation/Foundation.h>
#import <EXUpdates/EXUpdatesAppController.h>
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <UMCore/UMAppDelegateWrapper.h>
#import <AppsFlyerLib/AppsFlyerLib.h>
@interface AppDelegate : UMAppDelegateWrapper <RCTBridgeDelegate,EXUpdatesAppControllerDelegate>
@end
@interface AppDelegate2 : UIResponder <UIApplicationDelegate,AppsFlyerLibDelegate>
@end
在粘贴新代码之前,我的 AppDelegate.m 看起来像这样:
#import <Firebase.h>
#import "RNSailthruMobileBridge.h"
#import "AppDelegate.h"
#import "ReactNativeConfig.h"
#import <React/RCTLinkingManager.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <UMCore/UMModuleRegistry.h>
#import <UMReactNativeAdapter/UMNativeModulesProxy.h>
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h>
#import <EXSplashScreen/EXSplashScreenService.h>
#import <UMCore/UMModuleRegistryProvider.h>
#import <RNAppsFlyer.h>
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>
#import <UserNotifications/UserNotifications.h>
static void Initializeflipper(UIApplication *application) {
FlipperClient *client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[client addplugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
[client addplugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addplugin:[FlipperKitReactPlugin new]];
[client addplugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client start];
}
#endif
@interface AppDelegate () <RCTBridgeDelegate>
@property (nonatomic,strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
@property (nonatomic,strong) NSDictionary *launchOptions;
@end
@implementation AppDelegate
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Firebase
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}
#ifdef FB_SONARKIT_ENABLED
Initializeflipper(application);
#endif
self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]];
self.launchOptions = launchOptions;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
#ifdef DEBUG
[self initializeReactNativeApp];
#else
EXUpdatesAppController *controller = [EXUpdatesAppController sharedInstance];
controller.delegate = self;
[controller startAndShowLaunchScreen:self.window];
#endif
[super application:application didFinishLaunchingWithOptions:launchOptions];
return YES;
}
(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDevicetoken:(NSData *)devicetoken {
//Nsstring * token = [[Nsstring alloc] initWithData:devicetokenencoding:NSUTF8StringEncoding];
Nsstring *str = [Nsstring stringWithFormat:@"Device Token=%@",devicetoken];
NSLog(@"Device Token:%@",str);
//NSLog(@"Device token is called");
//const void *devTokenBytes = [devicetoken bytes];
//NSLog(@"Device Token");
}
(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
Nsstring *str = [Nsstring stringWithFormat: @"Error: %@",err];
NSLog(@"Error:%@",str);
}
(RCTBridge *)initializeReactNativeApp
{
// RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:self.launchOptions];
// RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"main" initialProperties:nil];
// then read individual keys like:
Nsstring *SAIL_THRU_SDK_KEY = [ReactNativeConfig envFor:@"SAIL_THRU_SDK_KEY"];
id<RCTBridgeDelegate> moduleInitialiser = [[RNSailthruMobileBridge alloc] initWithJSCodeLocation:[self sourceURLForBridge:nil] appKey:SAIL_THRU_SDK_KEY
moduleRegistryAdapter: _moduleRegistryAdapter]; // Obtain SDK key from your Sailthru Mobile app settings
RCTBridge * bridge = [[RCTBridge alloc] initWithDelegate:moduleInitialiser launchOptions:self.launchOptions];
RCTRootView * rootView = [[RCTRootView alloc]
initWithBridge:bridge
moduleName:@"main"
initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return bridge;
}
(NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
{
NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge];
// If you'd like to export some custom RCTBridgeModules that are not Expo modules,add them here!
return extraModules;
}
(NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
#ifdef DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[EXUpdatesAppController sharedInstance] launchAssetUrl];
#endif
}
(void)appController:(EXUpdatesAppController *)appController didStartWithSuccess:(BOOL)success {
appController.bridge = [self initializeReactNativeApp];
EXSplashScreenService *splashScreenService = (EXSplashScreenService *)[UMModuleRegistryProvider getSingletonModuleForClass:[EXSplashScreenService class]];
[splashScreenService showSplashScreenFor:self.window.rootViewController];
}
(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
[[AppsFlyerAttribution shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
[RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
return YES;
}
(BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(Nsstring *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
(BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *) options {
[[AppsFlyerAttribution shared] handleOpenUrl:url options:options];
return YES;
}
@end
...在我粘贴新代码后像这样:
#import <Firebase.h>
#import "RNSailthruMobileBridge.h"
#import "AppDelegate.h"
#import "ReactNativeConfig.h"
#import <React/RCTLinkingManager.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <UMCore/UMModuleRegistry.h>
#import <UMReactNativeAdapter/UMNativeModulesProxy.h>
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h>
#import <EXSplashScreen/EXSplashScreenService.h>
#import <UMCore/UMModuleRegistryProvider.h>
#import <RNAppsFlyer.h>
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>
#import <UserNotifications/UserNotifications.h>
static void Initializeflipper(UIApplication *application) {
FlipperClient *client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[client addplugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
[client addplugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addplugin:[FlipperKitReactPlugin new]];
[client addplugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client start];
}
#endif
@interface AppDelegate2 () <UIApplicationDelegate>
@end
@interface AppDelegate () <RCTBridgeDelegate>
@property (nonatomic,strong) NSDictionary *launchOptions;
@end
@implementation AppDelegate
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
########## below is new code from AppsFlyer instructions #########
// The userNotificationTypes below is just an example and may be changed depending on the app
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationoptionSound | UNAuthorizationoptionAlert | UNAuthorizationoptionBadge) completionHandler:^(BOOL granted,NSError * _Nullable error) {
}];
[[UIApplication sharedApplication] registerForRemoteNotifications];
// if you do not use push notificaiton in your app,uncomment the following line
//application.applicationIconBadgeNumber = 0;
}
########## above is new code from AppsFlyer instructions #########
// Firebase
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}
#ifdef FB_SONARKIT_ENABLED
Initializeflipper(application);
#endif
self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]];
self.launchOptions = launchOptions;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
#ifdef DEBUG
[self initializeReactNativeApp];
#else
EXUpdatesAppController *controller = [EXUpdatesAppController sharedInstance];
controller.delegate = self;
[controller startAndShowLaunchScreen:self.window];
#endif
[super application:application didFinishLaunchingWithOptions:launchOptions];
return YES;
}
(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDevicetoken:(NSData *)devicetoken {
//Nsstring * token = [[Nsstring alloc] initWithData:devicetokenencoding:NSUTF8StringEncoding];
Nsstring *str = [Nsstring stringWithFormat:@"Device Token=%@",add them here!
return extraModules;
}
(NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
#ifdef DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[EXUpdatesAppController sharedInstance] launchAssetUrl];
#endif
}
(void)appController:(EXUpdatesAppController *)appController didStartWithSuccess:(BOOL)success {
appController.bridge = [self initializeReactNativeApp];
EXSplashScreenService *splashScreenService = (EXSplashScreenService *)[UMModuleRegistryProvider getSingletonModuleForClass:[EXSplashScreenService class]];
[splashScreenService showSplashScreenFor:self.window.rootViewController];
}
(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
[[AppsFlyerAttribution shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
[RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
return YES;
}
(BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(Nsstring *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
(BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *) options {
[[AppsFlyerAttribution shared] handleOpenUrl:url options:options];
return YES;
}
########## below is new code from AppsFlyer instructions #########
(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDevicetoken:(NSData *)devicetoken {
[[AppsFlyerLib shared] registerUninstall:devicetoken];
}
@end
我在构建时收到此错误: Screenshot of the error in Xcode: .../AppDelegate.h:13:1: Duplicate interface definition for class 'AppDelegate'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。