-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
49 lines (42 loc) · 1.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { NativeModules, Platform } from 'react-native';
const isIOS = Platform.OS == 'ios';
export const ContactPickerStatus = {
SUCCESS: '10000',
NO_PERMISSION: '10001', // 无权限
USER_CANCELED: '10002', // 用户取消
OTHER_ERROR: '10003', // 位置错误
}
function pickContact() {
if (isIOS) {
return new Promise((resolve, reject) => {
NativeModules.RNContact.openContactPicker(result => {
if (result.code == ContactPickerStatus.SUCCESS) {
console.log(result);
let data = result.data;
let name = data.name.formatted;
data.name = name;
resolve(data);
} else {
reject({
code: result.code,
message: result.msg,
});
}
})
})
} else {
return new Promise((resolve, reject) => {
NativeModules.RNContact.openContactPicker().then(result => {
result.name = result.displayName;
resolve(result);
}).catch(error => {
reject({
code: error.code,
});
})
})
}
}
export default {
pickContact
}