Accessing contacts
To begin our exploration of what Xamarin.Mobile offers, let's access the address book within a Xamarin application. Let's improve the add friend feature of XamSnap by loading friends from the user's contact list. Make sure to add Xamarin.Mobile to the project from the Component Store for both the iOS and Android projects.
Navigate to the XamSnap
portable class library. First, we will need to split apart the IWebService
interface, by moving one method to a new IFriendService
interface:
public interface IFriendService { Task<User[]> GetFriends(string userName); }
Next, in FriendViewModel
, we will need to use the new IFriendService
interface instead of the old one:
private IFriendService friendService = ServiceContainer.Resolve<IFriendService>(); public async Task GetFriends() { //previous code here, use 'friendService' instead of 'service' Friends = await friendService.GetFriends(settings.User...