问题描述
目前项目中使用了pingpp-react-native这个模块,他在文档中说到需要在AppDelegate.m中加入以下代码,
//iOS 8 及以下- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { BOOL canHandleURL = [Pingpp handleOpenURL:url withCompletion:nil]; return canHandleURL;}//iOS 9 及以上- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { BOOL canHandleURL = [Pingpp handleOpenURL:url withCompletion:nil]; return canHandleURL;}
我的AppDelegate.m如下,目前只加了iOS9的代码,请问iOS8的那块代码如何加,看样子是要和RCTLinkingManager那块合并?
#import 'AppDelegate.h'#import <React/RCTBundleURLProvider.h>#import <React/RCTRootView.h>#import <React/RCTLinkingManager.h>#import 'SplashScreen.h'#import 'Pingpp.h'@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // 省略}- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{ return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation];}// 我添加的pingpp iOS9相关代码- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { BOOL canHandleURL = [Pingpp handleOpenURL:url withCompletion:nil]; return canHandleURL;}@end
问题解答
回答1:如果你需要适配iOS8,你就在两个方法判断一下版本就可以了