react-native-picup v1.0.21
react-native-picup
Getting started
Install library
From npm:
npm install react-native-picup
From yarn:
yarn add react-native-picup
Link native code
With autolinking (react-native 0.60+)
cd ios && pod install
Pre 0.60
react-native link react-native-picup
Manual installation
(skip if you didn't have problems with automatic installation)
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.picup.RNPicUpLibPackage;
to the imports at the top of the file - Add
new RNPicUpLibPackage()
to the list returned by thegetPackages()
method
Append the following lines to
android/settings.gradle
:include ':react-native-picup' project(':react-native-picup').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-picup/android')
Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':react-native-picup')
Insert the following lines inside repositories in
android/build.gradle
allprojects { repositories { ... google() jcenter() maven { url 'https://www.jitpack.io' } maven { url 'https://maven.google.com' } maven { url 'https://raw.githubusercontent.com/PicupMobile/PicupSDKv3/master/releases' } maven { url "https://mint.splunk.com/gradle/" } } }
Insert the following lines inside the dependencies block in
android/app/build.gradle
:dependencies { ... implementation 'com.picup.sdk:core_v3:5.0.5.3' }
There are two options to implement the hardening: Native JAVA and React-Native.
Native JAVA
Add in AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.READ_CALL_LOG" /> <uses-permission android:name="android.permission.DRAW_OVER_OTHER_APPS" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />
Replace in MainActivity
import android.content.Intent; import androidx.annotation.NonNull; import com.facebook.react.ReactActivity; import com.reactnativepicup.PicupModule; public class MainActivity extends ReactActivity { ... @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); PicupModule.onActivityResult(requestCode, resultCode, data); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults ) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); PicupModule.onRequestPermissionsResult(requestCode, permissions, grantResults); }
FCM (Firebase cloud messaging) integration
- Implement this section ONLY if your app is already using FCM:
Call onMessageReceived and onNewToken methods with the following code:
import messaging from '@react-native-firebase/messaging'; import PicUp from "react-native-picup"; messaging().onMessage( async (remoteMessage) => { ...write your code const { data, from } = remoteMessage; if (data?.sender === "PicUpMobile") { PicUp?.MessageReceived(data, from); } }, ); messaging().onTokenRefresh((token) => { ...write your code PicUp?.FcmOnNewToken(); });
For background messaging go to index.js|tsx in root folder
import { AppRegistry } from 'react-native'; import App from './App'; import { name as appName } from './app.json'; import messaging from '@react-native-firebase/messaging'; import PicUp from "react-native-picup"; messaging().setBackgroundMessageHandler(async (remoteMessage) => { ...write your code const { data, from } = remoteMessage; if (data?.sender === "PicUpMobile") { PicUp?.MessageReceived(data, from); } }); AppRegistry.registerComponent(appName, () => App);
IOS
- Add react-native-picup to your Podfile (with RN 0.60+ autolinking, this is not needed)
pod 'react-native-picup', :path => '../node_modules/react-native-picup'
and run pod install
from ios
folder
- Add Permission in plist
Go into your .plist file and add NSContactsUsageDescription with specific string
<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) need contact access</string>
Silent Push Notifications
To receive updates using silent push notifications:
Add Capabilities : Background Mode - Remote Notifications
Go into your MyReactProject/ios dir and open MyProject.xcworkspace workspace. Select the top project "MyProject" and select the "Signing & Capabilities" tab. Add a 2 new Capabilities using "+" button:
Background Mode
capability and tickRemote Notifications
.Push Notifications
capability
Create a push key:
Go to https://developer.apple.com/account/resources/authkeys and create a new APNS key. Download the key and save its Key ID.
Send push credentials to the PicUP team:
- APNS certificate p12 file and non-empty password (See Apple’s documentation)
- App ID (bundle identifier)
Ensure push entitlement:
Go to https://developer.apple.com/account/resources/identifiers, click your app ID, and check Push Notifications.
Register for remote notifications.
In your
AppDelegate.application(:didFinishLaunchingWithOptions:)
call:
Swift:
application.registerForRemoteNotifications()
Objective-C:
[application registerForRemoteNotifications];
- Pass the push notification:
Add to your AppDelegate
:
- Swift:
import PicUPSDKv3
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completion: @escaping (UIBackgroundFetchResult) -> Void
) {
if userInfo["sender"] as? String == "PicUpMobile" {
PicUpSDK.shared.didReceiveMessage(userInfo: userInfo) { result in
completion(.newData)
}
} else {
completion(.newData)
}
}
- Objective-C:
#import <PicUPSDKv3/PicUPSDKv3-Swift.h>
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
if ([userInfo[@"sender"] isEqualToString:@"PicUpMobile"]) {
[PicUpSDK.shared didReceiveMessageWithUserInfo:userInfo completion:^(PicUpResult * _Nonnull result) {
completionHandler(UIBackgroundFetchResultNewData);
}];
} else {
completionHandler(UIBackgroundFetchResultNewData);
}
}
- Pass the push token to PicUP.
Swift: In your application bridge header file
#import "Picup-Bridging-Header.h"
In your AppDelegate:
func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { let picup = Picup() picup.setPushToken(deviceToken); }
Objective-C: In your AppDelegate.m
#import "Picup-Bridging-Header.h" - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { Picup *picup = [[Picup alloc] init]; [picup setPushToken:deviceToken]; }
Background Fetch
You can refresh PicUP campaigns while your app is in the background, by using iOS Background Fetch.
First, Add the background fetch capability:
- Select your app target, and click Signing & Capabilities at the top bar.
- Click the + Capability at the top and add Background Modes.
- Check the Background fetch checkbox.
In your AppDelegate.application(:didFinishLaunchingWithOptions:)
call:
- Swift:
application.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
- Objective-C:
[application setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum];
Add to your AppDelegate
:
- Swift:
import PicUPSDKv3
func application(_ application: UIApplication,
performFetchWithCompletionHandler completion: @escaping (UIBackgroundFetchResult) -> Void
) {
PicUpSDK.shared.refresh(completion: { result in
completion(.newData)
})
}
- Objective-C:
#import <PicUPSDKv3/PicUPSDKv3-Swift.h>
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[PicUpSDK.shared refreshWithCompletion:^(PicUpResult * _Nonnull result) {
completionHandler(UIBackgroundFetchResultNewData);
}];
}
Methods
- You can call these methods in React
export function PicUpRegister(
name: string,
phone: string,
organizationCode: string,
security: string
): Promise<any>
export function setPermissions(json: string): Promise<any>;
export function MessageReceived(map: string, msg: string): Promise<any>;
export function FcmOnNewToken(): Promise<any>
export function enableService(): Promise<any>
export function disableService(): Promise<any>
export function clearData(): Promise<any>
export function isServiceEnabled(): boolean
export function isExternalPhoneStateEnabled(): boolean
export function isServiceAvailable(): boolean
export function saveWindowPosition(save: boolean): Promise<any>;
export function isWindowPositionSaved(): boolean;
export function setDebugMode(mode: boolean): Promise<any>;
export function setExternalPhoneStateOption(mode: boolean): Promise<any>;
export function isDebugMode(): boolean;
export function setOptoutOption(mode: boolean): Promise<any>;
export function isOptoutOptionActivated(): boolean;
export function setPermissionExternalMode(): Promise<any>;
export function setPermissionInternalMode(): Promise<any>;
export function getPermissionMode(): string;
export function isExternalPermissionsMode(): boolean;
export function disablePullRequestOption(mode: boolean): Promise<any>;
export function isPullRequestOptionDisabled(): boolean;
export function disableCampaignCheck(mode: boolean): Promise<any>;
export function isCampaignCheckDisabled(): boolean;
export function isIncomingDataBlocked(): boolean
export function blockIncomingData(mode: boolean): Promise<any>;
export function setInternalIncomingNumbersList(json: string): Promise<any>;
export function getInternalIncomingNumbersList(): string;
export function clearInternalIncomingNumbersList(): Promise<any>;
export function setInternalCampaignsJson(json: string): Promise<any>;
export function getInternalCampaignsJson(): string;
export function clearInternalCampaignsJson(): Promise<any>;
export function getImageSigningPublicKey(): string;
export function setImageSigningPublicKey(imageSigningPublicKey: string): Promise<any>;
setPermissions
``` export function setPermissions(json: string): Promise<any>; ``` - Example JSON is below ``` { "askingPermissions": { "nextAskingDays": 0, "maxAskingCount": 2, "reset": false }, "opt-in": { "enable": true }, "CallScreening": { "enable": true, "name": "CallScreening" }, "otherPermissions": [ { "enable": true, "name": "ReadPhoneState" }, { "enable": true, "name": "ReadCallLogs" }, { "enable": true, "name": "WriteContacts" } ], "drawPermission": { "enable": true, "name": "DrawOverlays", "askOrder": "Last", "explanation": { "message": "", "enable": true } } } ```
setImageSigningPublicKey
This function is used to set the image signing public key. this method needs to be called before PicUpRegister method.
```
import PicUp from 'react-native-picup';
const imageSigningPublicKey = "<PUBLIC_KEY>"; PicUp.setImageSigningPublicKey(imageSigningPublicKey);
PicUp.PicUpRegister(....)
```
Example
import * as React from 'react';
import {Button} from 'react-native';
import PicUp from 'react-native-picup';
export default () => {
React.useEffect(() => {
setPermissons();
}, []);
const onRegister = () => {
const user = {
name: "<NAME>",
phone: "<PHONE>",
code: "<CODE>",
secure: "<SECURE>",
};
PicUp.PicUpRegister(user.name, user.phone, user.code, user.secure).then(value => {
console.log('PicUpRegister:', value);
}).catch(reason => {
console.log("catch", reason);
});
};
const setPermissons = () => {
const PermissionsJson = {
"askingPermissions":
{
"nextAskingDays": 0,
"maxAskingCount": 2,
"reset": false
},
"opt-in":
{
"enable": true
},
"CallScreening":
{
"enable": true,
"name": "CallScreening"
},
"otherPermissions":
[
{"enable": true, "name": "ReadPhoneState"},
{"enable": true, "name": "ReadCallLogs"},
{"enable": true, "name": "WriteContacts"}
],
"drawPermission":
{
"enable": true,
"name": "DrawOverlays",
"askOrder": "Last",
"explanation":
{
"message": "",
"enable": true
}
}
};
PicUp.setPermissions(JSON.stringify(PermissionsJson)).then(value => {
console.log('setPermissions:', value);
}).catch(reason => {
console.log("catch", reason);
});
};
return (
<Button onPress={onRegister}>Register</Button>
)
};
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago