react-native-kiwi
A React Native wrapper for Kiwi subscription SDK
Getting started
$ npm install react-native-kiwi --save
Mostly automatic installation
$ react-native link react-native-kiwi
You will be prompted for the configUrl
.
Additional configuration
Android
Add the following in your android/app/build.gradle
file, so the react-native-kiwi
dependencies are properly included.
repositories {
flatDir {
dirs project(':react-native-kiwi').file('libs')
}
}
Add to your AndroidManifest.xml
the following line into the <application>
tag.
<application ...>
...
<meta-data android:name="com.movile.kiwi.sdk.applicationKey" android:value="@string/kiwi_app_key"/>
...
</application>
And in your strings.xml
file add your kiwi_app_key
<string name="kiwi_app_key">YOUR_APP_KEY</string>
iOS
-
Enable Swift in your project
If you're not using Swift yet you'll need to create a new empty .swift
file (can be empty.swift
) doing right click in your project + New File.
It should offer you to create a Bridging-Header
file: accept it.
As a result, you will have 2 new files (a .swift
and a .h
) and your project should build correctly now.
-
Include required frameworks in your project
Create a New Group named Frameworks
if it's not already created.
Then do a right click on that folder, select Add files to ..., navigate to <PROJECT_ROOT>/node_modules/react-native-kiwi/ios/Frameworks
and finally select both, Falcon.framework
and openssl.framework
.
Finally go to Build Settings / Framework Search Paths and add this path $(SRCROOT)/../node_modules/react-native-kiwi/ios/Frameworks
, so the project will include these when building.
-
Add required configuration by Falcon
-
In Build Phases
add a Copy Files
phase, select Frameworks
as destination and add Falcon.framework
-
Add a Run Script
phase with the following script
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
-
Init Falcon in your app boot
Add the following in your AppDelegate.m
file
NOTE: this guide was written assuming you've multiple environments. Could be simpler if you can hardcode the kiwiAppKey
and configJsonUrl
values.
#import <Falcon/Falcon.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString* kiwiAppKey = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"KiwiAppKey"];
NSString* configJsonUrl = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"KiwiConfigUrl"];
[Falcon startWithKiwiAppKey:kiwiAppKey jsonUrl:configJsonUrl completion:^(NSError* error) {
if (error != nil) {
NSLog(@"Error starting Falcon", error);
}
}];
}
-
Setup credentials and configuration values
In the Info.plist
file
<key>KiwiAppKey</key>
<string>$(KIWI_APP_KEY)</string>
<key>KiwiConfigUrl</key>
<string>$(KIWI_CONFIG_URL)</string>
Finally, for each environment add in the .xcconfig
KIWI_APP_KEY=<THE_KIWI_APP_KEY>
KIWI_CONFIG_URL=<THE_CONFIG_URL>
IMPORTANT! The double slash (//
) in the config url needs to be escaped using $()
so your file will end up like the following
KIWI_APP_KEY=abcd1234efgh5678
KIWI_CONFIG_URL=https:/$()/s3.amazonaws.com/project-name/config.json
Troubleshooting iOS setup
- iOS target needs to be 9.3
In order to support Swift you will need to change the target to 9.3 or newer
Falcon.h
not found
Check you've added $(SRCROOT)/../node_modules/react-native-kiwi/ios/Frameworks
in Build Settings / Framework Search Paths.
- dyld: Library not loaded: @rpath/Falcon.framework/Falcon (Reason: image not found)
You need to enable the Always Embed Swift Standard Libraries in Build Settings (see this)
- ld: warning: Auto-Linking library not found for -lswiftCoreImage
Chances are your project is not using Swift yet. Please check you've followed the Enable Swift in your project step
Usage
import Kiwi from 'react-native-kiwi'
Kiwi.getCountries().then(countries => console.log(countries))
Kiwi.getCarriers().then(carriers => console.log(carriers))
Kiwi.sendPincode(carrierId, phoneNumber)
Kiwi.loginWithPincode(carrierId, phoneNumber, pincode)
Kiwi.subscribe(carrierId, phoneNumber).then(response => console.log(response))
Kiwi.restoreSubscription(carrierId, phoneNumber).then(response => console.log(response))
Kiwi.redeemCode().then(response => console.log(response))
Kiwi.unsubscribe(carrierId, phoneNumber).then(response => console.log(response))
Kiwi.isSubscribed(carrierId).then(subscribed => console.log(subscribed))
Kiwi.submitFeedback(email, like, recommend, comment)
Kiwi.detectMsisdn(countryCode)