Problem fetching contact container Xamarin.iOS - c#

I got a problem with a little application I'm developing using Xamarin.iOS
My goal is simply to get every contacts present on an iPhone.
I have this code, it worked until now on my phone and at least 3 others.
Yesterday I added someone in my provisioning profile, since, I can't get any other value than 'null' on my phone when I try to fetch a container.
My phone is an iPhone 7 iOS 13.1.2 - I can't test it on any other phone until a little moment.
It still works on a simulator (iPhone 8 iOS 13.1).
I have the contact authorization request in my info.plist.
I just don't understand what getting 'null' means when fetching a default container ...
try
{
var keysTOFetch = new[] { CNContactKey.GivenName, CNContactKey.FamilyName, CNContactKey.Nickname, CNContactKey.JobTitle, CNContactKey.DepartmentName, CNContactKey.OrganizationName, CNContactKey.PostalAddresses, CNContactKey.UrlAddresses, CNContactKey.EmailAddresses, CNContactKey.PhoneNumbers };
NSError error;
CNContact[] contactList;
var ContainerId = new CNContactStore().DefaultContainerIdentifier; <---- //This where I get a null I never got before ...
if (ContainerId != null)
{
using (var predicate = CNContact.GetPredicateForContactsInContainer(ContainerId))
using (var store = new CNContactStore())
contactList = store.GetUnifiedContacts(predicate, keysTOFetch, out error);
var contacts = new List<UserContact>();
status = writeCSV(contactList, user);
}
else
Console.WriteLine("Didn't get any container identifier ..");
}
Apple documentation says it can return 'null' but without further explanation ..
Thanks a lot for your help

You are facing this issue on some phones and not other because the phone that work have only one container that it is trying load contacts from, while the phones that don't work have more than one container (i.e. Gmail, Exchange, iCloud accounts used to store contacts). So you are only loading the contacts from the account that is configured as the default, which has 0 contacts. Therefore, it would not load all contacts as requested.
Solution: Get all the containers and iterate over them to extract all contacts from each of them. You might be able to find some samples of it on Github.

Related

Is it possible to retrieve Facebook Leads from ads that aren't active?

I've developed a C# Windows (desktop) app to retrieve ad leads details from Facebook, which works - but only active ads.
Is there a way to get the details for all adds even if they are not active, or is this a Facebook default setting.
The URL I'm using is...
https://graph.facebook.com/[pageid]?access_token=[token]&fields=leadgen_forms{leads{form_id,ad_name,platform,created_time,field_data,custom_disclaimer_responses,retailer_item_id,is_organic}}
yes you can get leads even if they are not active.
If you are using sdk you can use the following code
$ads = $adset->getAds(array(
AdFields::NAME,
AdFields::CONFIGURED_STATUS,
AdFields::EFFECTIVE_STATUS,
AdFields::CREATIVE,
));
foreach ($ads as $ad) {
$ad_id = $ad->id;
$ad_name = $ad->name;
if($ad->configured_status=="ACTIVE"){}
}
check complete code here https://stackoverflow.com/a/56500241/2588592

UWP Make phone call not allowed in China, how to prevent deployment in China?

In my app I am trying to make it possible for the user to push a button and make a phone call
At the moment I was using this
if (phoneCallStore != null)
{
var lineGuid = await phoneCallStore.GetDefaultLineAsync();
if (lineGuid != Guid.Empty)
{
var phoneLine = await PhoneLine.FromIdAsync(lineGuid);
if (phoneLine != null && phoneLine.CanDial)
{
phoneLine.Dial(number, name);
}
}
}
But I was rejected by Microsoft as they say
Phone Call In Restricted Market: 2000.5 Phone Call In Restricted Market
The phonecall capability cannot be used in the application since it targets restricted markets (China).
EDIT
I tried removing China from markets, which fixed the problem.
But can I somehow, check if the user is from China?
The phonecall capability cannot be used in the application since it targets restricted markets (China).
Then when you submit your app you should exclude China from the list of target markets.

Retrieve all mobile devices Google Directory API in .NET Application

I want to Manage Device using Google API in my appilcation.How to retrieve all mobile/chrome OS device ?
CODE :
var listReq1 = service.Mobiledevices.List(serviceAccountEmail);
MobileDevices allUsers = listReq1.Execute();
Here,
serviceAccountEmail = "Service accounts Key" (Console.developer.google.com)
I am getting error like
Google.Apis.Requests.RequestError
Bad Request [400]
I tried using
var listReq= new Google.Apis.Admin.Directory.directory_v1.MobiledevicesResource.ListRequest(service,serviceAccountEmail);
Still not working ? I want all details of User just like Below Image
If you check the documentation for Mobiledevices: list
Retrieves a paginated list of all mobile devices for an account.
I will see that it takes a customer id as a parmater.
customerId The unique ID for the customer's Google account. As
an account administrator, you can also use the my_customer alias to
represent your account's customerId. The customerId is also returned
as part of the Users resource.
var listReq1 = service.Mobiledevices.List(customerId);
MobileDevices allUsers = listReq1.Execute();
You are sending service account email address which I really don't think is your customer id.

Facebook SDK Unity me/friends v2.2 returns 0

I have issue with getting friends id, name and picture, I have FB.API at Start and deserialize results at own method. I am using test users from Facebook Developers page.
Here is Start() code
FB.API("/me/friends", Facebook.HttpMethod.GET, DealWithFriendName);
Here is code to deserialize it so I can get id out of it. Havent yet coded to get name or picture
void DealWithFriendName(FBResult result)
{
if (result.Error != null)
{
Debug.Log("Problem with getting user data");
FB.API("/me/friends", Facebook.HttpMethod.GET, DealWithFriendName);
return;
}
Friends = Util.DeserializeJSONFriends(result.Text);
foreach (object id in Friends)
{
var entry = (Dictionary<string, object>)id;
}
Debug.Log(Friends.Count);
for(int i=0;i < Friends.Count;i++)
{
Debug.Log(Friends[i]);
}
}
Friend List count is 0 even if I have created 3 test users and they are friends with each other.
I am clueless what to try anymore.
Creating test accounts does not automatically associate them with your app. The default option is to have them not installed, which means when you query the friends API you will get the behavior #Tobi mentioned on Facebook API v2.x.
This is the like 1000th question for this topic. You only can get those friends which also use your app:
https://developers.facebook.com/docs/apps/changelog#v2_0_permissions
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/friends/
In Graph API v2.0, access to /me/friends is no longer part of the default (public_profile) permissions. We now require you to ask for the new permission user_friends. With this permission, /me/friends now returns the person's friends who are also using the app.

Adding contacts to People on Windows Phone 8.1 in C#

Is there a way to add contacts from my app to the People app on a Windows Phone 8.1? I looked at different things under the Contact class and nothing seems to work. There are different ways (like ContactManager, ContactPicket, etc.) to retrieve data but nothing seems to allow me to add a new contact as most of the stuff like SaveContactTask in Microsoft.Phone.Tasks is not implemented on WP 8.1.
J.
You don't have write access to the primary contact store on Windows Phone 8, but you have the ability to create your own contact store for the app which you can use to manage contacts created in your own app.
The mechanism is pretty simple:
using Windows.Phone.PersonalInformation;
public async void addPerson() {
var store = await ContactStore.CreateOrOpenAsync();
var contact = new StoredContact(store) {
DisplayName = "Mike Peterson"
};
var props = await contact.GetPropertiesAsync();
props.add(KnownContactProperties.Email, "mike#peterson.com");
props.add(KnownContactProperties.MobileTelephone, "+1 212 555 1234");
await contact.SaveAsync();
}
To inform the OS that you provide contact information, you need to add the ID_CAP_CONTACTS/Contacts capability to your app (in the Capabilities section of the appxmanifest). Contacts remain until the app is removed.
Private, owned by the app contacts are convenient for 'contact' data for the app.

Categories