addFriend
Feature Introduction
Description
Initiate a friend request to add someone as a friend.
Note
Related Callback: onFriendApplicationAdded
- iOS
- Android
- Flutter
- uni-app
- Browser/Electron/MiniProgram
- React-Native
- Unity
Function Prototype
Future<dynamic> addFriend({
required String userID,
String? reason,
String? operationID,
})
Input Parameters
Parameter Name | Parameter Type | Is Mandatory | Description |
---|---|---|---|
userID | String | Yes | User ID to be added |
reason | String | Yes | Request message |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
~ | ~ | Successful if no exception is thrown |
Code Example
await OpenIM.iMManager.friendshipManager.addFriend(userID: 'userID',reason: 'i want to');
// todo
Function Prototype
- (void)addFriend:(NSString *)userID
reqMessage:(NSString * _Nullable)reqMessage
onSuccess:(nullable OIMSuccessCallback)onSuccess
onFailure:(nullable OIMFailureCallback)onFailure;
Input Parameters
Parameter Name | Parameter Type | Is Mandatory | Description |
---|---|---|---|
userID | NSString | Yes | User ID to be added |
reqMessage | NSString | Yes | Request message |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
onSuccess | OIMSuccessCallback | Success Return |
onFailure | OIMFailureCallback | Failure Return |
Code Example
[OIMManager.manager addFriend:@""
reqMessage:@""
onSuccess:^(NSString * _Nullable data) {
} onFailure:^(NSInteger code, NSString * _Nullable msg) {
}];
Function Prototype
public void addFriend(OnBase<String> callBack, String uid,String reqMessage)
Input Parameters
Parameter Name | Parameter Type | Is Mandatory | Description |
---|---|---|---|
callBack | OnBase | Yes | Callback interface |
uid | String | Yes | User ID |
reqMessage | String | Yes | Message seen by the other user when requesting to add as a friend |
Return Result
Code Example
OpenIMClient.getInstance().friendshipManager.addFriend(new OnBase<String>(){...},uid,reqMessage)
Function Prototype
IMSDK.addFriend({
toUserID: string;
reqMsg: string;
}, operationID?: string): Promise<WsResponse>
Input Parameters
Parameter Name | Parameter Type | Is Mandatory | Description |
---|---|---|---|
toUserID | string | Yes | User ID to be added |
reqMsg | string | Yes | Friend request message |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<WsResponse> | Success callback |
Promise.catch() | Promise<WsResponse> | Failure callback |
Code Example
import { getSDK } from '@openim/wasm-client-sdk';
const IMSDK = getSDK();
// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();
// use in mini program
// import { getSDK } from '@openim/client-sdk';
// const IMSDK = getSDK();
IMSDK.addFriend({
toUserID: '',
reqMsg: '',
})
.then(() => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
IMSDK.asyncApi('addFriend', operationID: string, {
toUserID: string;
reqMsg: string;
}): Promise<void>
Input Parameters
Parameter Name | Parameter Type | Is Mandatory | Description |
---|---|---|---|
operationID | string | Yes | Operation ID, used for problem tracking, should be unique and preferably combined with current time and random number |
toUserID | string | Yes | User ID to be added |
reqMsg | string | Yes | Friend request message |
Return Result
Through the
openim-uniapp-polyfill
package, the function is turned into a Promise. When calling, you need to usethen
andcatch
to determine and handle success and failure callbacks.
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<void> | Success callback |
Promise.catch() | Promise<CatchResponse> | Failure callback |
Code Example
import IMSDK from 'openim-uniapp-polyfill';
IMSDK.asyncApi('addFriend', IMSDK.uuid(), {
toUserID: '',
reqMsg: '',
})
.then(() => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
OpenIMSDKRN.addFriend({
toUserID: string;
reqMsg: string;
}, operationID?: string): Promise<void>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
toUserID | string | Yes | User ID to be added |
reqMsg | string | Yes | Friend request message |
operationID | string | Yes | Operation ID, used for problem location, keep unique, suggest using current time and random number |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<void> | Callback on successful call |
Promise.catch() | Promise<CatchResponse> | Callback on failed call |
Code Example
import OpenIMSDKRN from "open-im-sdk-rn";
OpenIMSDKRN.addFriend({
toUserID: '',
reqMsg: '',
}, 'operationID');
.then(() => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
public static void AddFriend(OnBase<bool> cb, ApplyToAddFriendReq userIdReqMsg)
Input Parameter
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
cb | OnBase | Yes | Callback |
userIdReqMsg | ApplyToAddFriendReq | Yes | Add Friend Args |
Return Result
Code Example
IMSDK.AddFriend((suc,errCode,errMsg)=>{
},new ApplyToAddFriendReq(){
FromUserID = "",
ToUserID = "",
ReqMsg = "",
Ex = "",
});