Chilkat for React Native and Expo — the @chilkat/react-native package
Chilkat for React Native is the @chilkat/react-native
package on npm, a Nitro Module: one TypeScript class per Chilkat class
(Http, JsonObject, …) with full type declarations and inline documentation,
plain properties, exceptions for failures, a Promise-returning form of every long-running method,
and progress events as callback properties. It works in bare React Native apps and in Expo apps (development
builds and EAS Build) on iOS and Android. HTTP and REST, email (SMTP, POP3, IMAP, MIME), FTP, SFTP, SSH, zip and
compression, encryption, digital signatures, certificates, XML, JSON, sockets and more — the same
functionality as every other Chilkat product.
pod install on iOS, Gradle on Android) fetches the
prebuilt Chilkat library for the platform the first time, verifies it, and reuses it for later builds. The
offline builds section below covers build machines without internet access.
Jump to: Add to your project · Quick start · Supported targets · Async, progress and cancellation · Offline builds · How the API maps to TypeScript · Licensing
Documentation & Samples
- 📖 Chilkat React Native Reference Documentation — every class, method and property with its TypeScript signature
- 💻 Chilkat React Native Sample Code — ready-to-run examples
- 📦 @chilkat/react-native on npm — the same documentation is in the package's TypeScript declarations, so it shows in your editor
- 📝 Release Notes on the Chilkat blog
Add to your project
npm install @chilkat/react-native react-native-nitro-modules # bare React Native: cd ios && pod install # Expo (a development build or EAS Build; Expo Go cannot load native modules): npx expo prebuild
Then build and run as usual (npx react-native run-ios / run-android,
npx expo run:ios / run:android, or an EAS build). The package contains only TypeScript and
C++ sources; the Chilkat native library is fetched by the native build. On iOS, pod install downloads
chilkat-rn-ios.tar.gz; on Android, the Gradle build downloads
chilkat-rn-android.tar.gz — both for the exact package version, from
https://chilkatdownload.com/<version>/. Each archive's SHA-256 is checked
against the table shipped in the package (chilkat-checksums.json) before it is
unpacked under node_modules/@chilkat/react-native/native/. A verified copy is reused by
later builds, so the download happens once per Chilkat version per platform.
react-native-nitro-modules
(installed above), and Xcode 16.4 or later for iOS. Node must be on the PATH of the shell that runs
pod install or Gradle, because the native build runs the package's fetch script. No Chilkat headers
or libraries need to be installed by hand, and nothing is written in Swift, Kotlin or Java: the module is C++
compiled for both platforms. Web (react-native-web) is not supported, since the library is native code.
Quick start
import { Chilkat, Http, JsonObject } from '@chilkat/react-native'
// Any string unlocks the fully functional 30-day trial. Call once per app start.
Chilkat.unlockBundle('Anything for 30-day trial')
async function stars(): Promise<number> {
const http = new Http()
http.connectTimeout = 30
http.setRequestHeader('Accept', 'application/json')
try {
// The ...Async form runs on a native worker thread, so the UI keeps rendering.
const body = await http.quickGetStrAsync('https://api.github.com/repos/facebook/react-native')
const json = new JsonObject()
json.load(body)
return json.intOf('stargazers_count')
} catch (e) {
console.log((e as Error).message) // Http.quickGetStrAsync: <reason>
console.log(http.lastErrorText) // the full Chilkat log of the failed call
throw e
}
}
A method that can fail throws a plain Error instead of returning a status (a
...Async method rejects its promise with the same error). The error's
message names the class, the method and the reason; the object's lastErrorText holds the
full Chilkat log of the failed call. Objects release their native resources when garbage collected; call
dispose() to release them immediately (a large BinData, an open socket).
Supported targets
A prebuilt Chilkat library is published for each platform with every Chilkat release. The archive is what the native build downloads.
| Platform | Archive | Contents and notes |
|---|---|---|
| iOS | chilkat-rn-ios.tar.gz | Chilkat.xcframework with a device slice (arm64) and a simulator slice (arm64 and x86_64, for Apple silicon and Intel Macs), plus the C++ headers. Linked statically into the app by CocoaPods. The app's React Native minimum iOS version applies. |
| Android | chilkat-rn-android.tar.gz | Static libraries for arm64-v8a, armeabi-v7a, x86_64 and x86 (the x86 builds are for emulators), plus the C++ headers. Linked into the module's native library by CMake for each ABI the app builds (reactNativeArchitectures). 16 KB page sizes supported. The app's React Native minimum Android version applies. |
The archives are downloaded for the platform being built (iOS on a Mac running
pod install; Android wherever Gradle runs, including Windows and Linux). React Native for macOS or
Windows and react-native-web are not targets of this package; if you need one of them,
contact Chilkat support.
Async, progress and cancellation
Every method has a synchronous form, which blocks the JavaScript thread until Chilkat returns. Quick operations
(JSON, XML, hashing, encoding) are fine that way. Every method that can take a while (network, files, compression,
key generation) also has an ...Async form returning a Promise: the same
call on a native worker thread, settling on the JavaScript thread. Use those from UI code:
const body = await http.quickGetStrAsync(url) // instead of http.quickGetStr(url)
While an async call is pending, every other call on that object throws (the object is busy); other
objects are unaffected, so several downloads can run concurrently on several Http objects. Two things
are allowed on a busy object: abort(), which cancels the pending call (its promise then rejects), and
assigning the progress callbacks.
The event-capable classes (Http, Ftp2, SFtp, Zip,
Imap, …) have onPercentDone and onProgressInfo callback properties.
They are delivered on the JavaScript thread, so they can update React state directly — and for the same reason
they are useful with the ...Async methods (during a synchronous call the JavaScript
thread is busy inside Chilkat). There is no AbortCheck callback: to cancel, call
abort(), which Chilkat notices at its next progress check, at least every heartbeatMs
milliseconds on the classes that have that property.
const ftp = new Ftp2() ftp.hostname = host; ftp.username = user; ftp.password = pw ftp.heartbeatMs = 250 // let abort() take effect within a quarter second ftp.onPercentDone = (pct) => setProgress(pct) // 0..100, on the JS thread cancelButton.onPress = () => ftp.abort() await ftp.connectAsync() await ftp.getFileAsync('remote.dat', localPath)
The Task and TaskChain classes of other Chilkat
products are not part of this package; the ...Async methods use the same
Async names but return a JavaScript Promise.
Offline builds, vendoring, and your own Chilkat library
Build machines without internet access, or that must not download during a build, point the fetch script at a
local directory instead. Either set the environment variable CHILKAT_RN_LIB_DIR for the
shell that runs pod install or Gradle (on EAS Build, an environment variable or build secret), or add
the setting to the application's package.json:
{
"chilkat": { "libDir": "./vendor/chilkat" } // a relative path resolves against this package.json
}
The directory holds either the archives themselves (chilkat-rn-ios.tar.gz, chilkat-rn-android.tar.gz, verified against the package's checksum table) or their unpacked contents (ios/Chilkat.xcframework, ios/include, android/<abi>/libchilkat.a, android/include). With the setting present, nothing is downloaded. To populate that directory, download the archives once from a connected machine — the URLs are
https://chilkatdownload.com/<version>/chilkat-rn-ios.tar.gz
https://chilkatdownload.com/<version>/chilkat-rn-android.tar.gz
# for example, for @chilkat/react-native 11.6.1:
https://chilkatdownload.com/11.6.1/chilkat-rn-android.tar.gz
where <version> is the exact version of @chilkat/react-native you
depend on (the package version equals the Chilkat version). Each archive contains the library and headers,
license.pdf, a software bill of materials, and a VERSION
file. The SHA-256 of both archives is listed in chilkat-checksums.json inside the
package of the same version; a checksum mismatch fails the build rather than linking an unverified library.
The unpacked-directory form is also the way to build against your own build of the Chilkat C++ library: put its static library and headers in that layout and point libDir at it.
How the Chilkat API maps to TypeScript
| Chilkat | TypeScript |
|---|---|
| Class Http, JsonObject, CkDateTime | Http, JsonObject, CkDateTime — the same names, each both a type and a constructor: import { Http } from '@chilkat/react-native', then new Http(). Released by the garbage collector, or at once with dispose(). |
| Property ConnectTimeout | http.connectTimeout — a plain property; read-only ones are readonly |
| Method QuickGetStr, S3_DownloadFile | quickGetStr(), s3DownloadFile() — lowerCamelCase, same arguments |
| Method returning success/failure (bool) | returns void; throws an Error on failure |
| Method returning a string or an object (null on failure) | returns string, Cert, …; throws an Error where Chilkat would return null |
| Method answering a question (HasMember, IsUnlocked, TagEquals, …) | plain boolean |
| Method with events (QuickGetStr, SendEmail, …) | also quickGetStrAsync(): Promise<string> — the same call on a native worker thread; rejects where the synchronous form throws |
| LastErrorText | obj.lastErrorText (the error's message is its last informative line) |
| Numbers (int, unsigned long, int64, double) | number |
| Byte arrays | ArrayBuffer in both directions (and BinData for large or repeatedly used data). For a Uint8Array view u8, pass u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength). |
| Events (PercentDone, ProgressInfo) | Callback properties: obj.onPercentDone = (pct) => { ... }, obj.onProgressInfo = (name, value) => { ... }; delivered on the JavaScript thread |
| Event AbortCheck, Task.Cancel | obj.abort() cancels the pending ...Async call |
| Task, TaskChain | Not included; the ...Async methods return a Promise instead |
| UnlockBundle (the Global class) | Chilkat.unlockBundle(code) — a shorthand for new Global().unlockBundle(code); once per app start |
The reference documentation shows the exact TypeScript signature of every member, and the same text is in the package's type declarations, so your editor shows it as you type.
Licensing
This is the full-version Chilkat product. Chilkat libraries are
fully functional for a 30-day evaluation; passing any
non-empty string to Chilkat.unlockBundle starts the trial, and a purchased unlock code removes the time
limit. The license terms are in the LICENSE file of the package (and
license.pdf in both native archives). For questions, see the
reference documentation or
contact Chilkat support.