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.
... ...
And in your strings.xml
file add your kiwi_app_key
YOUR_APP_KEY
iOS
-
Enable Swift in your project If you're not using Swift yet you'll need to create a new empty
.swift
file (can beempty.swift
) doing right click in your project + New File. It should offer you to create aBridging-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
andopenssl.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 aCopy Files
phase, selectFrameworks
as destination and addFalcon.framework
-
Add a
Run Script
phase with the following scriptAPP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"# This script loops through the frameworks embedded in the application and# removes unused architectures.find "$APP_PATH" -name '*.framework' -type d |
-
-
Init Falcon in your app boot
Add the following in your
AppDelegate.m
fileNOTE: this guide was written assuming you've multiple environments. Could be simpler if you can hardcode the
kiwiAppKey
andconfigJsonUrl
values.#// ...- BOOLapplication: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* errorif error != nil;;// ... -
Setup credentials and configuration values
In the
Info.plist
fileKiwiAppKey$(KIWI_APP_KEY)KiwiConfigUrl$(KIWI_CONFIG_URL)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 followingKIWI_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 foundCheck 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
Kiwi // Retrieves the list of countries with the following format// iOS:// [{// id: 'AR',// code: 'AR',// name: 'Argentina',// ddi: 54// }]//// Android:// [{// current: false,// code: 'BR',// name: 'Brasil'// }] Kiwi // Retrieves the list of carriers with the following format// iOS:// [{// id: 1// countryCode: 'BR',// name: 'Vivo',// active: true,// shortCode: ...// }]//// Android:// [{// id: 1// sku: 'com.movile.marvel.br.vivo.1',// countryCode: 'BR',// countryName: 'Brasil',// pricing: 'R$3,99 por semana',// termsUrl: 'http://...someURL',// allowUnsubscription: true,// }] Kiwi // Send pincode with restoration purpose to that carrierId and phoneNumber//// @param carrierId (number) the carrier id// @param phoneNumber (string) the phone number used when the user subscribed Kiwi // Send pincode with restoration purpose to that carrierId and phoneNumber//// @param carrierId (number) the carrier id// @param phoneNumber (string) the phone number used when the user subscribed// @param pincode (string) the pin code received by SMS Kiwi // [Android only]// Starts the _subscription flow_//// @param carrierId (number)// @param phoneNumber (string) with just numbers//// Resolves with an object with the following format// {// subscribed: true|false // indicates if the user is subscribed or not// } Kiwi // [Android only]// Starts the _restore subscription flow_//// @param carrierId (number)// @param phoneNumber (string) with just numbers//// Resolves with an object with the following format// {// subscribed: true|false // indicates if the user is subscribed or not// } Kiwi // [Android only]// Starts the _code redeem flow_, the result should be stored because// there is no way to check the subscription.//// Resolves with an object with the following format// {// subscribed: true|false // indicates if the user is subscribed or not// } Kiwi // [Android only]// Starts the _unsubscription flow_//// @param carrierId (number)// @param phoneNumber (string) with just numbers//// Resolves with an object with the following format// {// subscribed: true|false // indicates if the user is subscribed or not// } Kiwi // Resolves with `true` if the user is subscribed for that carrierId, `false` if not// @param carrierId (number) Kiwi // [Android only]// Submit feedback and resolves with `null`//// @param email (string) an email address// @param like (number) from 1 to 5// @param recommend (number) from 1 to 5// @param comment (string) a free comment Kiwi // [Android only]// Detects the country, carrier and phone number if possible//// @param countryCode (string) the two-letter country code//// Resolves with an object with the following format// {// countryCode: 'AR',// carrierId: 12,// phoneNumber: '1140654321',// }