コード例 #1
0
        public void CheckPermission()
        {
            CNAuthorizationStatus authStatus = CNContactStore.GetAuthorizationStatus(CNEntityType.Contacts);

            if (authStatus == CNAuthorizationStatus.Denied || authStatus == CNAuthorizationStatus.Restricted)
            {
                Debug.WriteLine("Contacts Denied or Restricted");
                var okCancelAlertController = UIAlertController.Create("Alert", "Need permission to access contac", UIAlertControllerStyle.Alert);

                //Add Actions
                okCancelAlertController.AddAction(UIAlertAction.Create("Setting", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                {
                    MoveToSetting();
                }));
                okCancelAlertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));

                //Present Alert
                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(okCancelAlertController, true, null);
            }
            else if (authStatus == CNAuthorizationStatus.NotDetermined)
            {
                var store = new CNContactStore();
                store.RequestAccess(CNEntityType.Contacts, (granted, error) =>
                {
                    if (!granted)
                    {
                        var okCancelAlertController = UIAlertController.Create("Alert ", "Need permission to access contact", UIAlertControllerStyle.Alert);
                        //Add Actions
                        okCancelAlertController.AddAction(UIAlertAction.Create("Setting", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                        {
                            MoveToSetting();
                        }));
                        okCancelAlertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
                    }
                    else
                    {
                        //check = ContactEnum.Granted;
                        CustomPermissionStatus?.Invoke(ContactEnum.Granted, EventArgs.Empty);
                    }
                });
            }

            else
            {
                CustomPermissionStatus?.Invoke(ContactEnum.Granted, EventArgs.Empty);
            }
        }
コード例 #2
0
 public void RequestPermissionsResults(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
 {
     switch (requestCode)
     {
     case 1107:
     {
         if (grantResults[0] == Permission.Granted)
         {
             CustomPermissionStatus?.Invoke(ContactEnum.Granted, EventArgs.Empty);
         }
         else
         {
             CustomPermissionStatus?.Invoke(ContactEnum.Denied, EventArgs.Empty);
         }
     }
     break;
     }
 }
コード例 #3
0
        public void CheckPermission()
        {
            //MessagingCenter.Subscribe<MainPage, Dictionary>(this, "data", (s, a) => {
            //   // Events.Add($"Received message at {a.ToString()}");



            //});
            var check = GetcontactPermission();

            if (!check)
            {
                CustomPermissionStatus?.Invoke(ContactEnum.Denied, EventArgs.Empty);
                SetContactPermission();
            }
            else
            {
                CustomPermissionStatus?.Invoke(ContactEnum.Granted, EventArgs.Empty);
            }
        }