搜尋

首頁  >  問答  >  主體

react-native - react native ios AppDelegate.m的一個問題

目前專案中使用了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
迷茫迷茫2724 天前959

全部回覆(1)我來回復

  • PHPz

    PHPz2017-05-31 10:34:55

    如果你需要適配iOS8,你就在兩個方法判斷一下版本就可以了

    回覆
    0
  • 取消回覆