将本地ios项目appdelegate.m反应到appdelegate.swift

时间:2016-11-08 15:08:30

标签: ios objective-c swift react-native

我已将项目从objective-c转换为swift,因此我没有appdelegate.m和h和main.h,只有appdelegate.swift和objective-c桥接头。

AppDelegate.swift

import Foundation
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  var window: UIWindow?
  var bridge: RCTBridge!

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
    var jsCodeLocation: NSURL?
    jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURLForBundleRoot("index.ios", fallbackResource: nil)
    let rootView = RCTRootView(bundleURL:jsCodeLocation, moduleName: "MyApp", initialProperties: nil, launchOptions:launchOptions)

    self.bridge = rootView.bridge

    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    let rootViewController = UIViewController()

    rootViewController.view = rootView

    self.window!.rootViewController = rootViewController;
    self.window!.makeKeyAndVisible()

    return true
  }

  func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    return RCTLinkingManager.application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
  }

}

Objective-c桥接标题:

#import "RCTBundleURLProvider.h"
#import "RCTRootView.h"
#import "RCTLinkingManager.h"
#import "CodePush.h"
#import "RCTBridgeModule.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#import "RCTUtils.h"
#import "RCTConvert.h"
#import "sqlite3.h"

不幸的是它会抛出错误:

2016-11-08 16:02:30.393 [fatal][tid:main] No script URL provided. Make sure the packager is running or you have embedded a JS bundle in your application bundle.unsanitizedScriptURLString:((null))
2016-11-08 16:02:30.404 MyApp[76794:1727873] *** Terminating app due to uncaught exception 'RCTFatalException: No script URL provided. Make sure the packager is running or you have embedded a JS bundle in your application bundle.unsanitizedScriptURLString:((null))', reason: 'No script URL provided. Make sure the packager is running or you have embed...'

我做错了什么?

0 个答案:

没有答案