React IOS SDK
Add Invitereferrals Library to your Project
npm install react-native-invitereferrals
Link library to Project
react-native link react-native-invitereferrals
Note: React Native 0.59.0 Older & Not Using Cocoapods.
If you are not using Cocoapods &
react-native link react-native-invitereferrals
does not work.Then you have to manually link the library
A. Open node_modules/react-native-invitereferrals/ios
B. Drag and drop RNInvitereferrals.xcodeproj into XCode project folder Libraries
Cocoapods Install
React Native 0.60.0 or higher & Using Cocoapods.
Run this command from terminal
cd ios && pod install && cd ..
Initialize Sdk
1. Configure your info.plist
* Open info.plist of your project as source code (right click on info.plist and click on Open as >> Source code) and add the following code in it.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict/>
</dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Your_Project_Identifier_Name</string>
<key>CFBundleURLSchemes</key>
<array>
<string>yourURLscheme</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
<string>fb</string>
<string>twitter</string>
</array>
OR
-
You can simply open the info.plist and add the keys which works as same as above for this.
1.1. Add a new row by going to the menu and clicking Editor > Add Item. Setup a NSAppTransportSecurity as a Dictionary.
1.2. Added a Subkey called NSAllowsArbitraryLoads as Boolean and set its value to YES as in the following image.
1.3. Add a new row again and set up a URL Types item by adding a new item. Expand the URL Types key, expand Item 0, and add a new item, URL schemes. Fill in “appScheme” for Item 0 of URL schemes and your company identifier for the URL Identifier. Your file should resemble the image below when done.
1.4 Add a new row again and set up a LSApplicationQueriesSchemes as an Array. Fill in “whatsapp” for Item 0 , “fb” for item 1 and “twitter” for item 2 as in the following image.
2. App Delegate Initialization
- Include the header file in each .m file .
#import "RNInvitereferrals.h"
- Initialize the sdk in didFinishLaunchingWithOptions function.
[ RNInvitereferrals setupWithBrandId: BRANDID encryptedKey: @”ENCRYTEDKEY” ];
// Example:
// -(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions: (NSDictionary*)launchOptions {
// [RNInvitereferrals setupWithBrandId: 27XXX encryptedKey: @"685B3E09241XXXXXXXXXXXXXXXXXXXXXX"];
// }
Note:
In the above example, Dummy Brand ID and Encryption keys shown. Kindly login your IR_account to see your credentials.
- Add the following function in your AppDelegate file. openURL function that will check the deep linking and open your app from URL Scheme.
-(BOOL)application:(UIApplication*)app openURL:(NSURL*)urloptions:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
[RNInvitereferrals OpenUrlWithApplication: app Url: url];
return YES;
}
Plugin Methods
- To use plugin functions import module on your react page.
import Invitereferrals from 'react-native-invitereferrals';
Add Referral Button
- Add the following line in your custom button click. Replace CampaignID with the id of the referral campaign. Default campaignID will be applied if no campaignID specified.
Invitereferrals.inline_btn(“campaignID” );
// Example:-
// Invitereferrals.inline_btn(“1765”);
Note:
- For Default Campaign you can pass 0 as CampaignID:
Invitereferrals.inline_btn(“0”);
Pass User Details for Auto-Login (Single Sign In)
Invitereferrals.userDetails((String)name, (String)email, (String)mobile, (String)campaignID, (String)subscriptionID, (String)customValues, callback);
// Example:
// Invitereferrals.userDetails("abc", "[email protected]", "9876543210", “0”, null, null, this.successCallback );
Callback function be like this:
successCallback(msg){
alert(“success msg= ”+ msg);
}
Tracking Install / Register / Sale Events
- You call tracking() method to track events (i.e. install , register or sale):
Install
invitereferrals.tracking(“install”,null,”0”, null, null);
Register
invitereferrals.tracking(“register”,(String)EMAIL_ID,(String)PURCHASE_VALUE, null, null, successCallback, errorCallback);
// Example:
// invitereferrals.tracking(“register”,”[email protected]”,”0”, null, null, this.funSuccess, this.funError);
Success and Error Callback
funSuccess(msg){
alert(“success msg = ”+msg);
}
funError(msg){
alert(“error msg = ”+msg);
}
Sales
invitereferrals.tracking(“sale”,(String)ORDER_ID,(String)PURCHASE_VALUE, null, null, successCallback, errorCallback);
// Example:
// invitereferrals.tracking(“sale”,“abc123”,“99”, null, null,this.funSuccess, this.funError);
Show Welcome Message
- Show welcome message to customer if he comes through referral of his friend.
Invitereferrals.showWelcomeMessage();
Show Refer a friend Popup
- Just add the following line in the activity in which you want to show the referral program popup
Invitereferrals.invite((String)showRule);
// Example:
// Invitereferrals.invite("home");
Updated almost 3 years ago