Ios 错误:在react native上缺少FB SDK方法声明的上下文
我认为很容易找到类似的问题,但由于fb的github上没有问题,没有 我严格遵守这里的指示: 但它利用了这个错误,这清楚地表明@end后面的内容是一个问题。我知道我在编译器范围之外声明方法,但由于FB并没有关于这方面的全部信息,我不知道该怎么做Ios 错误:在react native上缺少FB SDK方法声明的上下文,ios,objective-c,react-native,Ios,Objective C,React Native,我认为很容易找到类似的问题,但由于fb的github上没有问题,没有 我严格遵守这里的指示: 但它利用了这个错误,这清楚地表明@end后面的内容是一个问题。我知道我在编译器范围之外声明方法,但由于FB并没有关于这方面的全部信息,我不知道该怎么做 /Users/Jean/dev/mysuperapp/ios/mysuperapp/AppDelegate.m:82:1: error: missing context for method declaration - (BOOL)application
/Users/Jean/dev/mysuperapp/ios/mysuperapp/AppDelegate.m:82:1: error: missing context for method declaration
- (BOOL)application:(UIApplication *)application
^
/Users/Jean/dev/mysuperapp/ios/mysuperapp/AppDelegate.m:91:1: error: missing context for method declaration
- (BOOL)application:(UIApplication *)application
^
/Users/Jean/dev/mysuperapp/ios/mysuperapp/AppDelegate.m:106:1: error: missing context for method declaration
- (void)applicationDidBecomeActive:(UIApplication *)application {
^
3 errors generated.
我发现了类似的问题,这是因为FBSDK的代码在@end之后,这似乎很明显。但是如果我在@end之前移动代码,编译器会抱怨缺少@end
我确信这只是为了理解编译器是如何工作的,但我一直坚持这一点。我根本不知道Objective-C,我对这个错误感到非常困惑
整个文件:
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "AppDelegate.h"
#import <CodePush/CodePush.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNFIRMessaging.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
#ifdef DEBUG
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
jsCodeLocation = [CodePush bundleURL];
#endif
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"cupido"
initialProperties:nil
launchOptions:launchOptions];
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];
// Added for FCM
[FIRApp configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
return YES;
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
[RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
}
#if defined(__IPHONE_11_0)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#else
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#endif
//You can skip this method if you don't want to use local notification
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[RNFIRMessaging didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
[RNFIRMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
@end
// AppDelegate.m
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
// Add any custom logic here.
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
];
// Add any custom logic here.
return handled;
}
// AppDelegate.m
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
/**
*版权所有(c)2015年至今,Facebook,Inc。
*版权所有。
*
*此源代码根据中的BSD样式许可证进行许可
*此源目录树的根目录中的许可证文件。额外补助金
*可以在同一目录的专利文件中找到专利权的名称。
*/
#导入“AppDelegate.h”
#进口
#进口
#进口
#导入“RNFIRMessaging.h”
@实现AppDelegate
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
NSURL*jsCodeLocation;
#ifdef调试
jsCodeLocation=[[RCTBundleURLProvider sharedSettings]jsBundleURLForBundleRoot:@“索引”后备资源:nil];
#否则
jsCodeLocation=[CodePush bundleURL];
#恩迪夫
RCTRootView*rootView=[[RCTRootView alloc]initWithBundleURL:jsCodeLocation
moduleName:@“cupido”
initialProperties:无
启动选项:启动选项];
rootView.backgroundColor=[[UIColor alloc]initWithRed:1.0f绿色:1.0f蓝色:1.0f alpha:1];
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UIViewController*rootViewController=[UIViewController新建];
rootViewController.view=rootView;
self.window.rootViewController=rootViewController;
[self.window makeKeyAndVisible];
//添加了FCM
[FIRApp配置];
[[UNUserNotificationCenter currentNotificationCenter]设置委托:self];
返回YES;
}
-(void)userNotificationCenter:(UNUserNotificationCenter*)中心将使用completionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler呈现通知:(UNNotification*)通知
{
[RNfirmMessageing将呈现通知:带有completionHandler的通知:completionHandler];
}
#如果已定义(\uuuuIphone\u11\u0)
-(void)userNotificationCenter:(UNUserNotificationCenter*)center未收到NotificationResponse:(UNNotificationResponse*)带有completionHandler的响应:(void(^)(void))completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response with completionHandler:completionHandler];
}
#否则
-(void)userNotificationCenter:(UNUserNotificationCenter*)center未收到NotificationResponse:(UNNotificationResponse*)带有completionHandler的响应:(void(^)()completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response with completionHandler:completionHandler];
}
#恩迪夫
//如果不想使用本地通知,可以跳过此方法
-(无效)应用程序:(UIApplication*)应用程序未收到本地通知:(UILocalNotification*)通知{
[RNFIRMessaging DiReceiveLocalNotification:notification];
}
-(void)application:(UIApplication*)application-didReceiveEmotentification:(非Null NSDictionary*)userInfo-fetchCompletionHandler:(非Null void(^)(UIBackgroundFetchResult))completionHandler{
[RNFIRMessaging DidReceiveMemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
@结束
//AppDelegate.m
#进口
-(BOOL)应用程序:(UIApplication*)应用程序
didFinishLaunchingWithOptions:(NSDictionary*)启动选项{
[[FBSDKApplicationDelegate sharedInstance]应用程序:应用程序
didFinishLaunchingWithOptions:launchOptions];
//在这里添加任何自定义逻辑。
返回YES;
}
-(BOOL)应用程序:(UIApplication*)应用程序
openURL:(NSURL*)url
选项:(NSDictionary*)选项{
BOOL handled=[[FBSDKApplicationDelegate sharedInstance]应用程序:应用程序
openURL:url
sourceApplication:options[UIApplicationOpenUrlOptions SourceApplicationKey]
注释:选项[UIApplicationOpenUrlOptions注释键]
];
//在这里添加任何自定义逻辑。
处理退货;
}
//AppDelegate.m
#进口
-(无效)应用IDBECOMEACTIVE:(UIApplication*)应用{
[FBSDKAppEvents activateApp];
}
你能这样试试吗
说明中的代码应放在@implementation-AppDelegate
和@end
之间
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "AppDelegate.h"
#import <CodePush/CodePush.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNFIRMessaging.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
#ifdef DEBUG
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
jsCodeLocation = [CodePush bundleURL];
#endif
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"cupido"
initialProperties:nil
launchOptions:launchOptions];
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];
// Added for FCM
[FIRApp configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
[RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
}
#if defined(__IPHONE_11_0)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#else
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#endif
//You can skip this method if you don't want to use local notification
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[RNFIRMessaging didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
[RNFIRMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
];
// Add any custom logic here.
return handled;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
@end
/**
*版权所有(c)2015年至今,Facebook,Inc。
*版权所有。
*
*此源代码根据中的BSD样式许可证进行许可
*此源目录树的根目录中的许可证文件。额外补助金
*可以在同一目录的专利文件中找到专利权的名称。
*/
#导入“AppDelegate.h”
#进口
#进口
#进口
#导入“RNFIRMessaging.h”
#进口
@实现AppDelegate
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
NSURL*jsCodeLocation;
#ifdef调试
jsCodeLocation=[[RCTBundleURLProvider sharedSettings]jsBundleURLForBundleRoot:@“索引”后备资源:nil];
#否则
jsCodeLocation=[CodePush bundleURL];
#恩迪夫
RCTRootView*rootView=[[RCTRootView alloc]initWithBundleURL:jsCodeLocation
moduleName:@“cupido”
initialProperties:无
启动选项:启动选项];
rootView.backgroundColor=[[UIColor alloc]initWithRed:1.0f绿色:1.0f蓝色:1.0f alpha:1];
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UIViewController*rootViewController=[UIViewController新建];
rootViewController.view=rootView;
self.window.rootViewController=rootViewController;
[self.windowma]
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "AppDelegate.h"
#import <CodePush/CodePush.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import "RNFIRMessaging.h" // FCM
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"cupidoIos"
initialProperties:nil
launchOptions:launchOptions];
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];
// Added for FCM
[FIRApp configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
return YES;
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
[RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
}
#if defined(__IPHONE_11_0)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#else
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#endif
//You can skip this method if you don't want to use local notification
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[RNFIRMessaging didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
[RNFIRMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
@end