示例#1
0
    private void OnGUI()
    {
        KitchenSink.OnGUIBack();

        GUILayout.BeginArea(new Rect(50, 50, Screen.width - 100, Screen.height / 2 - 50));

        //this is the original way of how objective C use call back functions: Delegates using separate files.
        //in this case the file is PeoplePickerNavigationControllerDelegate.cs
        //we have have it easier to use delegates instead of creating new files for each delegate.
        //see examples above.  Ex: PersonalXT.CalendarAccess += delegate( ....
        if (GUILayout.Button("pick/select from contacts", GUILayout.ExpandHeight(true)))
        {
            ABPeoplePickerNavigationController picker = new ABPeoplePickerNavigationController();
            if (pickerDelegate == null)
            {
                pickerDelegate = new PeoplePickerNavigationControllerDelegate();
            }
            picker.peoplePickerDelegate = pickerDelegate;
            UIApplication.deviceRootViewController.PresentViewController(picker, true, null);
        }

        if (GUILayout.Button("get all contacts", GUILayout.ExpandHeight(true)))
        {
            Log("Address book authorization status: " + ABAddressBook.GetAuthorizationStatus());

            var addressBook = ABAddressBook.Create(null, null);
            addressBook.RequestAccess(delegate(bool granted, NSError error) {
                Log("Granted: " + granted);

                //convienent function to get the names of the contacts
                string[] contactList = PersonalXT.GetAllContactNames();
                for (int i = 0; i < contactList.Length; i++)
                {
                    Log("Contact " + i + ": " + contactList[i]);
                }
            });
        }

        if (GUILayout.Button("add new contacts", GUILayout.ExpandHeight(true)))
        {
            addNewContact();
        }

        if (GUILayout.Button("init Calendar and show events within 30 days", GUILayout.ExpandHeight(true)))
        {
            checkEventStoreAccessForCalendar();
        }

        if (GUILayout.Button("add an event for tomorrow", GUILayout.ExpandHeight(true)))
        {
            addEventForTomorrow();
        }

        if (GUILayout.Button("add alarm to events", GUILayout.ExpandHeight(true)))
        {
            createAlarmForEvents();
        }

        if (GUILayout.Button("add reminder with geolocation of current location", GUILayout.ExpandHeight(true)))
        {
            PersonalXT.RequestReminderAccess();
        }

        if (GUILayout.Button("reverse geocode happiest place on earth", GUILayout.ExpandHeight(true)))
        {
            CLLocation location = new CLLocation(33.809, -117.919);
            CLGeocoder geocoder = new CLGeocoder();
            geocoder.ReverseGeocodeLocation(location, delegate(object[] placemarks, NSError error) {
                if (error != null)
                {
                    Debug.Log(error.LocalizedDescription());
                }
                else
                {
                    foreach (var p in placemarks)
                    {
                        var placemark = p as CLPlacemark;

                        Debug.Log("placemark: " + placemark.name + "\n"
                                  + ABAddressFormatting.ABCreateString(placemark.addressDictionary, true));
                    }
                }
            });
        }

        if (GUILayout.Button("Significant location change", GUILayout.ExpandHeight(true)))
        {
            if (!CLLocationManager.LocationServicesEnabled() || !CLLocationManager.SignificantLocationChangeMonitoringAvailable())
            {
                Debug.Log("Significant change monitoring not available.");
            }
            else
            {
//				CLLocationManager manager = new CLLocationManager();

                manager.StartMonitoringSignificantLocationChanges();
            }
        }


        //commented out remove all events and reminders so users don't accidentally remove important events

        /*
         * if (GUILayout.Button("remove all Events", GUILayout.ExpandHeight(true))) {
         *      PersonalXT.RemoveAllEvents();
         *      Log ("Removed events");
         * }
         *
         * if (GUILayout.Button("remove all Reminders", GUILayout.ExpandHeight(true))) {
         *      PersonalXT.GetAllReminders(); //you can get all the reminders and handle them in line 59 above
         *      //PersonalXT.RemoveAllReminders(); //or you can simply call removeAllReminders
         * }*/

        GUILayout.EndArea();
        OnGUILog();
    }