在我的代码中,我使用ABPeoplePickerNavigationController来选择人.用户从联系人列表中选择人员后,我查看指定人员记录是否有任何电话号码:
- (BOOL) peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
ABMutableMultiValueRef phones;
phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
if (phones == nil || ABMultiValueGetCount(phones) == 0)
{
return NO;
}
// other code....
}
Run Code Online (Sandbox Code Playgroud)
我创建了联系人,为其添加了电话号码并测试了我的代码.在iOS 5中,此代码运行良好. phones变量包含一个电话号码.
但在iOS 6中,将联系人链接到facebook帐户后,phone变量不包含任何值.
取消与Facebook帐户的联系后,一切都运行良好.
如何通过此方法读取人员电话号码?
- (BOOL) peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
Run Code Online (Sandbox Code Playgroud)
UPD
如果我在上面的函数中返回YES,那么在函数中
(BOOL) peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
Run Code Online (Sandbox Code Playgroud)
我可以正常方式阅读所有人的电话号码.那么为什么我不能在第一个函数中读取它们呢?
我正在尝试使用HttpURLConnection执行post请求,但不知道如何正确执行.
我可以使用以下代码使用AndroidAsyncHttp客户端成功执行请求:
AsyncHttpClient httpClient = new AsyncHttpClient();
httpClient.addHeader("Content-type", "application/json");
httpClient.setUserAgent("GYUserAgentAndroid");
String jsonParamsString = "{\"key\":\"value\"}";
RequestParams requestParams = new RequestParams("request", jsonParamsString);
httpClient.post("<server url>", requestParams, jsonHttpResponseHandler);
Run Code Online (Sandbox Code Playgroud)
在桌面计算机上使用curl可以执行相同的请求:
curl -A "GYUserAgentAndroid" -d 'request={"key":"value"}' '<server url>'
Run Code Online (Sandbox Code Playgroud)
这两种方法都给了我服务器的预期响应.
现在我想使用HttpURLConnection做同样的请求.问题是我不知道如何正确地做到这一点.我尝试过这样的事情:
URL url = new URL("<server url>");
HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
httpUrlConnection.setDoOutput(true);
httpUrlConnection.setDoInput(true);
httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.setRequestProperty("User-Agent", "GYUserAgentAndroid");
httpUrlConnection.setRequestProperty("Content-Type", "application/json");
httpUrlConnection.setUseCaches (false);
DataOutputStream outputStream = new DataOutputStream(httpUrlConnection.getOutputStream());
// what should I write here to output stream to post params to server ?
outputStream.flush();
outputStream.close();
// get …Run Code Online (Sandbox Code Playgroud)