Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nativescript/ios

NativeScript18.4kApache-2.08.9.2

NativeScript Runtime for iOS

NativeScript, iOS, runtime

readme

Getting Started

To start diving into the v8 iOS runtime make sure you have Xcode and Homebrew installed, and then run the following

# Install CMake
brew install cmake

# (Optional) Install clang-format to format the code
brew install clang-format

# To avoid errors, you might need to link cmake to: /usr/local/bin/cmake
# xcode doesn't read your profile during the build step, which causes it to ignore the PATH
sudo ln -s /usr/local/bin/cmake $(which cmake)

# Clone repo
git clone https://github.com/NativeScript/ios.git

# Initialize and clone the submodules
cd ios
git submodule update --init

# Ensure that you have the required llvm binaries for building the metadata generator
./download_llvm.sh

sudo gem install xcodeproj
sudo gem install cocoapods

# Open the runtime in Xcode
open v8ios.xcodeproj

Select the TestRunner target and an emulator and hit Run (the play button).

Screenshot 2020-09-09 at 18 25 43

This should take a while, but once built the emulator should start and show a black screen (this is normal). In this phase the app will run all the built-in tests, and report the results to the console:

Runtime initialization took 55ms
2020-09-09 18:30:37.797265+0200 TestRunner[14285:1238340] CONSOLE LOG: Application Start!
2020-09-09 18:30:38.288740+0200 TestRunner[14285:1238340] No implementation found for exposed method "nonExistingSelector"
2020-09-09 18:30:49.720055+0200 TestRunner[14285:1238340] CONSOLE LOG: SUCCESS: 684 specs, 0 failures, 0 skipped, 0 disabled in 11.81s.

If all tests pass, everything is good! At this point you can make changes to the runtime, add breakpoints and step through with the debugger. In the next section we'll see how to attach the runtime to an existing NativeScript application allowing us to debug runtime issues in actual apps.

Attaching the runtime to a NativeScript app

In the existing app, we need to prepare the Xcode project using ns prepare ios. This will create a folder named platforms/ios and in there a <appname>.xcworkspace (or .xcodeproject but note the following...).

IMPORTANT: You can only attach the runtime to a .xcworkspace project (not a .xcodeproj project). If your app's platforms/ios folder does not contain a .xcworkspace file yet, you can do the following:

Add a new file App_Resources/iOS/Podfile with the following contents:

pod 'IQKeyboardManager'

Now ns clean and prepare again with ns prepare ios. This will make sure when the iOS project is generated that you end up with a .xcworkspace file so attaching the v8 runtime source works properly.

You can now open the platforms/ios/{project-name}.xcworkspace file in Xcode and then drag the v8ios.xcodeproj from the root of this repo under the <appname> in the Xcode sidebar.

Screenshot 2020-09-09 at 18 46 18

Remove the NativeScript.xcframework and TKLiveSync.xcframework from the General tab, as we will no longer be using the framework from node_modules and instead will use the source directly:

Screenshot 2020-09-09 at 18 47 23

Hitting Run in Xcode should start the app in the simulator, and we can now add breakpoints to the runtime and step through it with the debugger. To apply changes to the javascript, make sure you run ns prepare ios to re-bundle it into the platforms/ios folder.

Only required when running on a physical device

Add the Nativescript.framework and TKLiveSync.framework from the v8ios workspace:

Screen Shot 2021-04-12 at 11 49 10 AM

Troubleshooting

If you encounter vague errors like this when building your app with the runtime included (This has been observed sometimes while Profiling apps in Xcode):

/path/to/ios/NativeScript/inspector/src/base/atomicops.h:311:11: No matching function for call to 'Relaxed_Load'

This is most likely related to Build Active Architecture Only setting in Xcode for various targets (your app and the included v8ios runtime). You should check to make sure your app Build Settings and the v8ios targets NativeScript and TKLiveSync Build Settings are set to YES for both Debug and Release. See this reference: https://github.com/QuickBlox/quickblox-ios-sdk/issues/993#issuecomment-379656716

Overview

POC showing the {N} iOS runtime running with the V8 engine.

Supported architectures:

  • x86_64
  • arm64

iOS deployment target:

  • 9.0

The --jitless mode in which V8 is running is explained in the following document

Updating/Building V8 engine source

In order to build the V8 engine for iOS and produce the static libraries used in the NativeScript iOS runtime follow these steps:

Prerequisites:

git clone https://github.com/NativeScript/ios.git
cd ios

You will need Google depot_tools

  • If you have not cloned the repo yet, clone the following and export a path setting so they can be referenced properly:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

// copy/paste this command in current terminal window:
export PATH=`pwd`/depot_tools:"$PATH"
  1. Fetch the latest v8 source (or specific version):

If you have an existing v8 source fetched, delete the folder, and fetch it fresh each time updates are needed.

// IMPORTANT: Make sure you are inside the clone of this repo...
cd ios

// Fetch v8 source:
fetch v8

This will create a v8 repo folder automatically checking out the master branch.

Always check https://omahaproxy.appspot.com/ for the specific version you intend to build.

  1. Ensure you checkout the version you intend to build:
cd v8

// for example:
git checkout 9.2.230.18

gclient sync

This will checkout a specific tag and fetch additional dependencies for building the intended version.

  1. Apply patches from v8 updates to the iOS runtime:
npm run apply-patches

NOTE: Oftentimes the patches may not apply immediately and can run into issues like this:

error: patch failed: BUILD.gn:538
error: BUILD.gn: patch does not apply
error: patch failed: src/inspector/inspector_protocol_config.json:21
error: src/inspector/inspector_protocol_config.json: patch does not apply
~/Documents/ios/v8/build ~/Documents/ios/v8 ~/Documents/ios
error: patch failed: config/ios/ios_sdk.gni:32
error: config/ios/ios_sdk.gni: patch does not apply

You can look at each patch failure, for example BUILD.gn: patch does not apply, you can apply the patch manually instead. This can be done by opening the ./v8.patch file and applying each patch manually to the corresponding file.

  1. Build v8 source:
npm run build-v8-source

Troubleshooting build errors

  • Example failure 1:
@Mac ios % npm run build-v8-source

> @nativescript/ios@8.1.0 build-v8-source
> ./build_v8_source.sh

~/Documents/ios/v8 ~/Documents/ios
Building for out.gn/x64-release (simulator)
Done. Made 212 targets from 92 files in 4004ms
ninja: Entering directory `out.gn/x64-release'
ninja: error: unknown target 'v8_libsampler'

In this case, the v8_libsampler module no longer needs to be built specifically as a target, therefore the MODULES inside the build_v8_source.sh can be modified to remove the target of v8_libsampler and the build can be invoked again.

  • Example failure 2:
ERROR at //build/config/ios/ios_sdk.gni:181:33: Script returned non-zero exit code.
    ios_code_signing_identity = exec_script("find_signing_identity.py",

Automatic code signing identity selection was enabled but could not
find exactly one codesigning identity matching "Apple Development".

Check that the keychain is accessible and that there is exactly one
valid codesigning identity matching the pattern. Here is the parsed
output of `xcrun security find-identity -v -p codesigning`:

  1) 1ABE0***********************************: "Apple Development: Your Name (U4********)"
  2) CB529***********************************: "Apple Distribution: Your Org (29********)"
  3) BACD5***********************************: "Apple Development: Your Name (VV********)"
  4) 0D42D***********************************: "Apple Development: Your Team (D3********)"
  5) 055BA***********************************: "Apple Development: Your Name (GF********)"
  6) A5306***********************************: "Apple Development: Your Name (9V***********)"
    6 valid identities found

If this occurs you can manually modify v8/build/config/ios/ios_sdk.gni. A property named ios_code_signing_identity. You can set that explicitly to one of your code signing identities. You can use the command it suggests to list out your identities in full: xcrun security find-identity -v -p codesigning - Copy the id and paste it as the value of ios_code_signing_identity.

You will want to make ios_code_signing_identity_description an empty string so the final change should look something like this:

# Explicitly select the identity to use for codesigning. If defined, must
# be set to a non-empty string that will be passed to codesigning. Can be
# left unspecified if ios_code_signing_identity_description is used instead.
ios_code_signing_identity = "...your-id..."

# Pattern used to select the identity to use for codesigning. If defined,
# must be a substring of the description of exactly one of the identities by
# `security find-identity -v -p codesigning`.
ios_code_signing_identity_description = ""
  1. If building of the v8 source succeeds, Verify the build output.

The compiled fat static libraries will be placed inside the v8/dist folder.

Building a Distribution Package

  1. Bump the version in package.json

  2. Run: npm run update-version (This will update the runtime headers with version info)

  3. Build & pack: npm run build

This will create: dist/npm/nativescript-ios-{version}.tgz NPM package ready for publishing.

changelog

8.9.2 (2025-03-11)

Bug Fixes

Reverts

  • "feat: visionOS unit tests" (f26d72c)

8.9.1 (2025-02-28)

Features

8.9.0 (2025-02-24)

Bug Fixes

  • handle gc protection in runtime run loop (#264) (5e8214d)
  • possible race condition extending native class (8b932a3)
  • URL: allow undefined 2nd args and fix pathname return value (#263) (4219038)

Features

8.8.3-alpha.0 (2024-12-05)

Bug Fixes

  • handle gc protection in runtime run loop (78b5e37)
  • possible race condition extending native class (8b932a3)

8.8.2 (2024-09-06)

Bug Fixes

  • ensure same mtime for js and code cache to prevent loading old code caches (#261) (055b042)
  • revert visionOS changes to iOS project template (55c5c51)

8.8.1 (2024-07-10)

Features

8.8.0 (2024-07-09)

Bug Fixes

  • ensure copy rule copy *.hpp headers (3b13e9d)

Features

  • add [@deprecation](https://github.com/deprecation) and [@since](https://github.com/since) docs (#246) (daceac1)
  • add protocol information to native types (#247) (6286203)
  • allow embedding into existing apple host projects (#231) (7ab180a)
  • expose __dateTimeConfigurationChangeNotification (#220) (5088f5f)
  • JSI support for BigInt, Initial TypedArrays & ArrayBuffer creation (#204) (4cd869d)
  • use messaging object to pass message to workers (#233) (7ded0c3)
  • xcode 16 support (#254) (6ec9a8f)

8.7.2 (2024-05-16)

Bug Fixes

8.7.1 (2024-04-26)

Bug Fixes

8.7.0 (2024-04-08)

Bug Fixes

  • only generate metadata for the targeted arch (#236) (17a5c5f)
  • Xcode 15.3+ not setting TARGET_OS_IPHONE correctly (#242) (0d52056)

Features

8.6.3 (2023-11-08)

Bug Fixes

  • prevent crashes during isolate disposal (3d70c11)

8.6.2 (2023-11-01)

Bug Fixes

  • only reset timer persistent if Isolate is valid (4379583)

8.6.0 (2023-10-09)

Bug Fixes

  • bridge release adapters (#224) (70b1802)
  • delay isolate disposal when isolate is in use (5a6c2ee)
  • don't suppress timer exceptions (0c4b819)
  • fix setInterval not repeating correctly (022893f)
  • prevent JS function to native block leak (#223) (a6d7332)

Features

  • add interop.stringFromCString (#228) (185c12d)
  • add native timers (#221) (119470f)
  • add timer strong retainer annotation (efef961)
  • log the fullMessage with more details about the error (#229) (d67588c)
  • use node logic for globals and modules (#215) (a66cc42)

8.5.2 (2023-05-24)

Bug Fixes

  • Cache shared_ptr leak (8236cf3)
  • FunctionWrapper isolate-level leak (0c4c017)
  • move TARGETED_DEVICE_FAMILY to xcconfig to allow override (#211) (2e5f5f1)
  • remove quotes for TARGETED_DEVICE_FAMILY (157dda7)
  • soif on runtime destruction (7e24de8)

Features

  • re-enabled inspector protocol handling (#202) (c100f72)

8.5.1 (2023-03-30)

Bug Fixes

  • incorrect wrapper in indexed array access (#206) (b689434)

8.5.0 (2023-03-28)

Bug Fixes

  • block isolate validation condition (17a7299)
  • Build and link to v8_heap_base and v8_heap_base_headers (3ebd066)
  • Correctly initialize context in inspector client init() (92b38ea)
  • create empty metadata-bin files to satisfy XCode dep checks (0e349fc)
  • Don't disconnect inspector when frontend connects (d2d3b65)
  • don't null runloop on Promise proxy (826a395)
  • don't try to free blocks that not owned by the BlockWrapper (d4e9b08)
  • drain the microtask queue after devtools message (de77365)
  • Implement console.log inspector with Runtime protocol (eaa8dd7)
  • Mac Catalyst build (#189) (8980c0f)
  • Re-enable inspector code (14faf01)
  • resolve PromiseProxy context memory leak (#193) (21de81d)
  • set metadata-generator deployment target to 11.0 (#198) (75cf79f)
  • use BigInt for pointers (#199) (6db3184)

Features

8.4.1 (2023-01-16)

Bug Fixes

8.4.0 (2022-11-30)

Bug Fixes

  • string: initWithBytes instead of UTF8 string (b72dcf6)
  • support null characters on NSString marshalling (705346f)

Features

  • drop perIsolateCaches_ in favor of v8 data slots (44daeb3)
  • inline frequently used methods, add caches, thread safety, and use static allocation when possible (44e60d0)
  • use spinlocks for selector maps (c5a8863)

Performance Improvements

8.3.3 (2022-08-13)

Bug Fixes

8.3.2 (2022-07-23)

Bug Fixes

8.3.1 (2022-07-22)

Bug Fixes

  • memory leak on ArgConverter::ConstructObject (1129d15)
  • memory leak on ArrayAdapter, DictionaryAdapter and NSDataAdapter (#170) (1e1abe2)
  • misspelling on MetaType (f6e0500)
  • xcode14 build phase files (#169) (3b1eafc)

Features

  • add debug runtime detail log handling (cfe59d4)
  • add support for reasons on assertion failure (#172) (e185014)
  • improve crash report details (#142) (f0a49c0)

Performance Improvements

  • cache swizzled selector construction (#173) (de6506b)

8.2.3 (2022-03-30)

Bug Fixes

  • use serial queues and revert string copy changes (#156) (e8681ff)

8.2.2 (2022-03-22)

Bug Fixes

  • inspector: ensure socket message is copied and stored (#155) (3098976)
  • only delay promise resolution when needed (#154) (f46c425)

8.2.0 (2022-03-07)

Bug Fixes

  • don't leak code cache data (#146) (c580098)
  • lock isolate before handle_scope (#149) (3c23fd8)
  • only warn once about WeakRef.clear() deprecation. (#140) (fc0f18c)
  • prevent crashes during onuncaughterror (#141) (65be29b)
  • retain instance on init (2d6f455)
  • runtime init and reset handling (1893356)
  • take into account null terminated C strings (#132) (63ac554)
  • TypeEncoding might be initialized with random data (#144) (02d681e)

Features

  • add support for custom ApplicationPath (391ef8f)
  • expose PerformMicrotaskCheckpoint (#133) (f868384)
  • run app from NativeScript initializer instead of static method (#137) (a676ecf)
  • support Xcode 13.3 and iOS 15.4 (#150) (1e0c0ce)

8.1.0 (2021-09-08)

Bug Fixes

  • check if a static method is already set (#122) (1f40861)
  • isolate dispose on app exit handling (57ec2ec)
  • memory leak when marshalling C string parameters (#127) (f946828)
  • general memory leak fixes 62dff97

Features

7.2.0

Features

Bug Fixes

  • breakpoint debugging

7.1.1

This release should restore debugging in chrome-devtools.

7.1.0

Features

Bug Fixes

7.0.6

Bug Fixes

7.0.5

Bug Fixes

7.0.4

Features

Bug Fixes

7.0.3

Bug Fixes

7.0.2(-rc)

Issue

7.0.1

Features

Bug Fixes

7.0.0-beta.3-v8 (2020-03-09)

Features

Bug Fixes

6.5.0-beta.2-v8 (2020-01-28)

Features

Bug Fixes

6.4.0-beta.1-v8 (2020-01-14)

Features

  • SIMD support
  • NSError** output parameters support
  • Global js error handler

Bug Fixes

6.2.0-alpha.2-v8 (2019-09-18)

Features

  • Script code caching
  • iOS Deployment Target = 9.0
  • Log statements are sent to stderr using the NSLog function
  • Wrap native method calls into try/catch statements and throw javascript exception for every caught NSException

Bug Fixes

  • The global.performance object is no longer declared as readonly #2

6.2.0-alpha.1-v8 (2019-09-18)

Initial public release