FMX.AddressBook.TCustomAddressBook.RequestPermission

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure RequestPermission;

C++

void __fastcall RequestPermission(void);

Properties

Type Visibility Source Unit Parent
procedure
function
public
FMX.AddressBook.pas
FMX.AddressBook.hpp
FMX.AddressBook TCustomAddressBook

Description

Sends a request to access a device Address Book.

Use this method to send a request to access a device Address Book. To process the system response, use the OnPermissionRequest event handler.

Important You should call the RequestPermission method before accessing any functionality of a device Address Book. Otherwise, your application cannot work with a device Address Book and might fail. For example, you can call the RequestPermission method in the TForm.onShow event handler.

Note On iOS devices, RequestPermission is an asynchronous method.

Examples

To clarify, consider the following examples. These code snippets illustrate how to implement the OnShow and OnPermissionRequest event handlers to request a permission to access a device Address Book.


Delphi:

procedure TForm1.FormShow(Sender: TObject);
begin
  AddressBook1.RequestPermission;
end;

procedure TForm1.AddressBook1PermissionRequest(ASender: TObject;
  const AMessage: string; const AAccessGranted: Boolean);
begin
  if AAccessGranted then
  begin
   // Do something with Address Book
  end
  else
    ShowMessage('You cannot access Address Book. Reason: ' + sLineBreak + AMessage);
end;

C++Builder:

void __fastcall TForm1::FormShow(TObject *Sender) {
	AddressBook1->RequestPermission();	
}


void __fastcall TForm1::AddressBook1PermissionRequest(TObject *ASender,
	const UnicodeString AMessage, const bool AAccessGranted) {
	if (AAccessGranted) {

        // Do something with Address Book 		

	}
	else {
		ShowMessage("You cannot access Address Book. Reason: " + sLineBreak + AMessage);
	}
}



For more information and samples, see Mobile Tutorial: Using an Address Book Component (iOS and Android).

See Also