[MonoTouch] iOS 6 ABAddressBook.RequestAccess example

2012-09-28 Thread Stanley
Hi there,

I'm new to both C# and iOS and I'm looking for an example of how to
implement ABAddressBook.RequestAccess. Here is my code so far:

private bool GetAddressBook ()
{
if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
NSError err;
iPhoneAddressBook = ABAddressBook.Create (out err);
var authStatus = ABAddressBook.GetAuthorizationStatus();
if (authStatus != ABAuthorizationStatus.Authorized) {
// iPhoneAddressBook.RequestAccess <-- is this where to 
do it?? how??
using (var alert = new UIAlertView("Contacts 
Permission", "We need your
permission to access your phone contacts. Please go to Settings > Privacy >
Contacts", null, "OK", null)) {
alert.Show ();  
return false;
}
}
return err == null;
} else {
iPhoneAddressBook = new ABAddressBook ();
return true;
}
}

Thanks for your help guys.




--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/iOS-6-ABAddressBook-RequestAccess-example-tp4657314.html
Sent from the MonoTouch mailing list archive at Nabble.com.
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] iOS 6 ABAddressBook.RequestAccess example

2012-09-29 Thread Nic Wise
You can use it like this:


iPhoneAddressBook.RequestAccess(delegate(bool granted,
NSError error) {
//do something in here
//this is called back with granted = true if the user
allowed it.
   });

This is an async call, so your app will continue to run until the user
says yes or no. Then the delegate gets called.

You dont need to show the dialog yourself - iOS does that for you. You
just need to handle when they say yes/no.

On Sat, Sep 29, 2012 at 3:40 AM, Stanley  wrote:
> Hi there,
>
> I'm new to both C# and iOS and I'm looking for an example of how to
> implement ABAddressBook.RequestAccess. Here is my code so far:
>
> private bool GetAddressBook ()
> {
> if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
> NSError err;
> iPhoneAddressBook = ABAddressBook.Create (out err);
> var authStatus = ABAddressBook.GetAuthorizationStatus();
> if (authStatus != ABAuthorizationStatus.Authorized) {
> // iPhoneAddressBook.RequestAccess <-- is this where 
> to do it?? how??
> using (var alert = new UIAlertView("Contacts 
> Permission", "We need your
> permission to access your phone contacts. Please go to Settings > Privacy >
> Contacts", null, "OK", null)) {
> alert.Show ();
> return false;
> }
> }
> return err == null;
> } else {
> iPhoneAddressBook = new ABAddressBook ();
> return true;
> }
> }
>
> Thanks for your help guys.
>
>
>
>
> --
> View this message in context: 
> http://monotouch.2284126.n4.nabble.com/iOS-6-ABAddressBook-RequestAccess-example-tp4657314.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> ___
> MonoTouch mailing list
> MonoTouch@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch



-- 
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] iOS 6 ABAddressBook.RequestAccess example

2012-09-30 Thread Stanley
Thanks Nic. I was hoping to get an example of blocking until the delegate
was called, and how that would fit into the code I posted. I'll have a
crack at it somehow. At least you've given me the the correct syntax for
the RequestAccess call.

Ta muchly.

On 29 September 2012 18:37, Nic Wise [via MonoTouch] <
ml-node+s2284126n4657316...@n4.nabble.com> wrote:

> You can use it like this:
>
>
> iPhoneAddressBook.RequestAccess(delegate(bool granted,
> NSError error) {
> //do something in here
> //this is called back with granted = true if the user
> allowed it.
>});
>
> This is an async call, so your app will continue to run until the user
> says yes or no. Then the delegate gets called.
>
> You dont need to show the dialog yourself - iOS does that for you. You
> just need to handle when they say yes/no.
>
> On Sat, Sep 29, 2012 at 3:40 AM, Stanley <[hidden 
> email]>
> wrote:
>
> > Hi there,
> >
> > I'm new to both C# and iOS and I'm looking for an example of how to
> > implement ABAddressBook.RequestAccess. Here is my code so far:
> >
> > private bool GetAddressBook ()
> > {
> > if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
> > NSError err;
> > iPhoneAddressBook = ABAddressBook.Create (out err);
> > var authStatus = ABAddressBook.GetAuthorizationStatus();
> > if (authStatus != ABAuthorizationStatus.Authorized) {
> > // iPhoneAddressBook.RequestAccess <-- is this
> where to do it?? how??
> > using (var alert = new UIAlertView("Contacts
> Permission", "We need your
> > permission to access your phone contacts. Please go to Settings >
> Privacy >
> > Contacts", null, "OK", null)) {
> > alert.Show ();
> > return false;
> > }
> > }
> > return err == null;
> > } else {
> > iPhoneAddressBook = new ABAddressBook ();
> > return true;
> > }
> > }
> >
> > Thanks for your help guys.
> >
> >
> >
> >
> > --
> > View this message in context:
> http://monotouch.2284126.n4.nabble.com/iOS-6-ABAddressBook-RequestAccess-example-tp4657314.html
> > Sent from the MonoTouch mailing list archive at Nabble.com.
> > ___
> > MonoTouch mailing list
> > [hidden email] 
> > http://lists.ximian.com/mailman/listinfo/monotouch
>
>
>
> --
> Nic Wise
> t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
> b. http://www.fastchicken.co.nz/
>
> mobileAgent (for FreeAgent): get your accounts in your pocket.
> http://goo.gl/IuBU
> Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
> Earnest: Self-employed? Track your business expenses and income.
> http://earnestapp.com
> Nearest Bus: find when the next bus is coming to your stop.
> http://goo.gl/Vcz1p
> London Bike App: Find the nearest Boris Bike, and get riding!
> http://goo.gl/Icp2
> ___
> MonoTouch mailing list
> [hidden email] 
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
> --
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://monotouch.2284126.n4.nabble.com/iOS-6-ABAddressBook-RequestAccess-example-tp4657314p4657316.html
>  To unsubscribe from iOS 6 ABAddressBook.RequestAccess example, click 
> here
> .
> NAML
>




--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/iOS-6-ABAddressBook-RequestAccess-example-tp4657314p4657326.html
Sent from the MonoTouch mailing list archive at Nabble.com.___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] iOS 6 ABAddressBook.RequestAccess example

2012-09-30 Thread René Ruppert
Check out Miguel's answer here: 
http://stackoverflow.com/questions/4248244/iphone-uialertview-modal
It will give you an idea how to block code execution. 

Grüße, René

Am 01.10.2012 um 00:59 schrieb Stanley :

> Thanks Nic. I was hoping to get an example of blocking until the delegate was 
> called, and how that would fit into the code I posted. I'll have a crack at 
> it somehow. At least you've given me the the correct syntax for the 
> RequestAccess call. 
> 
> Ta muchly.
> 
> On 29 September 2012 18:37, Nic Wise [via MonoTouch] <[hidden email]> wrote:
>> You can use it like this: 
>> 
>> 
>> iPhoneAddressBook.RequestAccess(delegate(bool granted, 
>> NSError error) { 
>> //do something in here 
>> //this is called back with granted = true if the user 
>> allowed it. 
>>}); 
>> 
>> This is an async call, so your app will continue to run until the user 
>> says yes or no. Then the delegate gets called. 
>> 
>> You dont need to show the dialog yourself - iOS does that for you. You 
>> just need to handle when they say yes/no. 
>> 
>> On Sat, Sep 29, 2012 at 3:40 AM, Stanley <[hidden email]> wrote:
>> 
>> > Hi there, 
>> > 
>> > I'm new to both C# and iOS and I'm looking for an example of how to 
>> > implement ABAddressBook.RequestAccess. Here is my code so far: 
>> > 
>> > private bool GetAddressBook () 
>> > { 
>> > if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) { 
>> > NSError err; 
>> > iPhoneAddressBook = ABAddressBook.Create (out err); 
>> > var authStatus = ABAddressBook.GetAuthorizationStatus(); 
>> > if (authStatus != ABAuthorizationStatus.Authorized) { 
>> > // iPhoneAddressBook.RequestAccess <-- is this 
>> > where to do it?? how?? 
>> > using (var alert = new UIAlertView("Contacts 
>> > Permission", "We need your 
>> > permission to access your phone contacts. Please go to Settings > Privacy 
>> > > 
>> > Contacts", null, "OK", null)) { 
>> > alert.Show (); 
>> > return false; 
>> > } 
>> > } 
>> > return err == null; 
>> > } else { 
>> > iPhoneAddressBook = new ABAddressBook (); 
>> > return true; 
>> > } 
>> > } 
>> > 
>> > Thanks for your help guys. 
>> > 
>> > 
>> > 
>> > 
>> > -- 
>> > View this message in context: 
>> > http://monotouch.2284126.n4.nabble.com/iOS-6-ABAddressBook-RequestAccess-example-tp4657314.html
>> > Sent from the MonoTouch mailing list archive at Nabble.com. 
>> > ___ 
>> > MonoTouch mailing list 
>> > [hidden email] 
>> > http://lists.ximian.com/mailman/listinfo/monotouch
>> 
>> 
>> 
>> -- 
>> Nic Wise 
>> t.  > target="_blank">+44 7788 592 806 | @fastchicken | 
>> http://www.linkedin.com/in/nicwise
>> b. http://www.fastchicken.co.nz/
>> 
>> mobileAgent (for FreeAgent): get your accounts in your pocket. 
>> http://goo.gl/IuBU
>> Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
>> Earnest: Self-employed? Track your business expenses and income. 
>> http://earnestapp.com
>> Nearest Bus: find when the next bus is coming to your stop. 
>> http://goo.gl/Vcz1p
>> London Bike App: Find the nearest Boris Bike, and get riding! 
>> http://goo.gl/Icp2
>> ___ 
>> MonoTouch mailing list 
>> [hidden email] 
>> http://lists.ximian.com/mailman/listinfo/monotouch
>> 
>> 
>> If you reply to this email, your message will be added to the discussion 
>> below:
>> http://monotouch.2284126.n4.nabble.com/iOS-6-ABAddressBook-RequestAccess-example-tp4657314p4657316.html
>> To unsubscribe from iOS 6 ABAddressBook.RequestAccess example, click here.
>> NAML
> 
> 
> View this message in context: Re: iOS 6 ABAddressBook.RequestAccess example
> Sent from the MonoTouch mailing list archive at Nabble.com.
> ___
> MonoTouch mailing list
> MonoTouch@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] iOS 6 ABAddressBook.RequestAccess example

2012-10-01 Thread Nic Wise
You could put whatever code you want to be called in another method,
then call it from the block. If it's already authorized, just call it.

private bool GetAddressBook ()
{
if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
NSError err;
iPhoneAddressBook = ABAddressBook.Create (out err);
var authStatus = ABAddressBook.GetAuthorizationStatus();
if (authStatus != ABAuthorizationStatus.Authorized) {

 iPhoneAddressBook.RequestAccess(delegate(bool granted,
NSError error) {
if (granted) {//CALL YOUR METHOD HERE}
   });
} else {
//CALL YOUR METHOD HERE
}
return err == null;
} else {
iPhoneAddressBook = new ABAddressBook ();
//CALL YOUR METHOD HERE
return true;
}
}

However, if you are using an async function, but working in a sync
manner, than you may need to refactor either the above bit, or your
calling code.

On Sun, Sep 30, 2012 at 11:59 PM, Stanley  wrote:
> Thanks Nic. I was hoping to get an example of blocking until the delegate
> was called, and how that would fit into the code I posted. I'll have a crack
> at it somehow. At least you've given me the the correct syntax for the
> RequestAccess call.
>
> Ta muchly.
>
> On 29 September 2012 18:37, Nic Wise [via MonoTouch] <[hidden email]> wrote:
>>
>> You can use it like this:
>>
>>
>> iPhoneAddressBook.RequestAccess(delegate(bool granted,
>> NSError error) {
>> //do something in here
>> //this is called back with granted = true if the user
>> allowed it.
>>});
>>
>> This is an async call, so your app will continue to run until the user
>> says yes or no. Then the delegate gets called.
>>
>> You dont need to show the dialog yourself - iOS does that for you. You
>> just need to handle when they say yes/no.
>>
>> On Sat, Sep 29, 2012 at 3:40 AM, Stanley <[hidden email]> wrote:
>>
>> > Hi there,
>> >
>> > I'm new to both C# and iOS and I'm looking for an example of how to
>> > implement ABAddressBook.RequestAccess. Here is my code so far:
>> >
>> > private bool GetAddressBook ()
>> > {
>> > if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
>> > NSError err;
>> > iPhoneAddressBook = ABAddressBook.Create (out err);
>> > var authStatus = ABAddressBook.GetAuthorizationStatus();
>> > if (authStatus != ABAuthorizationStatus.Authorized) {
>> > // iPhoneAddressBook.RequestAccess <-- is this
>> > where to do it?? how??
>> > using (var alert = new UIAlertView("Contacts
>> > Permission", "We need your
>> > permission to access your phone contacts. Please go to Settings >
>> > Privacy >
>> > Contacts", null, "OK", null)) {
>> > alert.Show ();
>> > return false;
>> > }
>> > }
>> > return err == null;
>> > } else {
>> > iPhoneAddressBook = new ABAddressBook ();
>> > return true;
>> > }
>> > }
>> >
>> > Thanks for your help guys.
>> >
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> > http://monotouch.2284126.n4.nabble.com/iOS-6-ABAddressBook-RequestAccess-example-tp4657314.html
>> > Sent from the MonoTouch mailing list archive at Nabble.com.
>> > ___
>> > MonoTouch mailing list
>> > [hidden email]
>> > http://lists.ximian.com/mailman/listinfo/monotouch
>>
>>
>>
>> --
>> Nic Wise
>> t.  > target="_blank">+44 7788 592 806 | @fastchicken |
>> http://www.linkedin.com/in/nicwise
>>
>> b. http://www.fastchicken.co.nz/
>>
>> mobileAgent (for FreeAgent): get your accounts in your pocket.
>> http://goo.gl/IuBU
>> Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
>> Earnest: Self-employed? Track your business expenses and income.
>> http://earnestapp.com
>> Nearest Bus: find when the next bus is coming to your stop.
>> http://goo.gl/Vcz1p
>> London Bike App: Find the nearest Boris Bike, and get riding!
>> http://goo.gl/Icp2
>> ___
>> MonoTouch mailing list
>> [hidden email]
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>>
>> 
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://monotouch.2284126.n4.nabble.com/iOS-6-ABAddressBook-RequestAccess-example-tp4657314p4657316.html
>> To unsubscribe from iOS 6 ABAddressBook.RequestAccess example, click here.
>> NAML
>
>
>
> 
> View this message in context: Re: iOS 6 ABAddressBook.RequestAccess example
>
> Sent from the MonoTouch mailing list archive at Nabble.com.
>
> __

Re: [MonoTouch] iOS 6 ABAddressBook.RequestAccess example

2012-10-01 Thread Stanley
Thanks again Nic. This code really needs to be called synchronously because
the app can't continue without access to contacts at this point. What I
ended up doing is checking for authorisation earlier, before loading the
view that required access. Certainly appreciate the help :)

On 1 October 2012 17:37, Nic Wise [via MonoTouch] <
ml-node+s2284126n465732...@n4.nabble.com> wrote:

> You could put whatever code you want to be called in another method,
> then call it from the block. If it's already authorized, just call it.
>
> private bool GetAddressBook ()
> {
> if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
> NSError err;
> iPhoneAddressBook = ABAddressBook.Create (out err);
> var authStatus = ABAddressBook.GetAuthorizationStatus();
> if (authStatus != ABAuthorizationStatus.Authorized) {
>
>  iPhoneAddressBook.RequestAccess(delegate(bool
> granted,
> NSError error) {
> if (granted) {//CALL YOUR METHOD HERE}
>});
> } else {
> //CALL YOUR METHOD HERE
> }
> return err == null;
> } else {
> iPhoneAddressBook = new ABAddressBook ();
> //CALL YOUR METHOD HERE
> return true;
> }
> }
>
> However, if you are using an async function, but working in a sync
> manner, than you may need to refactor either the above bit, or your
> calling code.
>
> On Sun, Sep 30, 2012 at 11:59 PM, Stanley <[hidden 
> email]>
> wrote:
>
> > Thanks Nic. I was hoping to get an example of blocking until the
> delegate
> > was called, and how that would fit into the code I posted. I'll have a
> crack
> > at it somehow. At least you've given me the the correct syntax for the
> > RequestAccess call.
> >
> > Ta muchly.
> >
> > On 29 September 2012 18:37, Nic Wise [via MonoTouch] <[hidden email]>
> wrote:
> >>
> >> You can use it like this:
> >>
> >>
> >> iPhoneAddressBook.RequestAccess(delegate(bool granted,
> >> NSError error) {
> >> //do something in here
> >> //this is called back with granted = true if the user
> >> allowed it.
> >>});
> >>
> >> This is an async call, so your app will continue to run until the user
> >> says yes or no. Then the delegate gets called.
> >>
> >> You dont need to show the dialog yourself - iOS does that for you. You
> >> just need to handle when they say yes/no.
> >>
> >> On Sat, Sep 29, 2012 at 3:40 AM, Stanley <[hidden email]> wrote:
> >>
> >> > Hi there,
> >> >
> >> > I'm new to both C# and iOS and I'm looking for an example of how to
> >> > implement ABAddressBook.RequestAccess. Here is my code so far:
> >> >
> >> > private bool GetAddressBook ()
> >> > {
> >> > if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
> >> > NSError err;
> >> > iPhoneAddressBook = ABAddressBook.Create (out err);
> >> > var authStatus =
> ABAddressBook.GetAuthorizationStatus();
> >> > if (authStatus != ABAuthorizationStatus.Authorized) {
> >> > // iPhoneAddressBook.RequestAccess <-- is
> this
> >> > where to do it?? how??
> >> > using (var alert = new UIAlertView("Contacts
> >> > Permission", "We need your
> >> > permission to access your phone contacts. Please go to Settings >
> >> > Privacy >
> >> > Contacts", null, "OK", null)) {
> >> > alert.Show ();
> >> > return false;
> >> > }
> >> > }
> >> > return err == null;
> >> > } else {
> >> > iPhoneAddressBook = new ABAddressBook ();
> >> > return true;
> >> > }
> >> > }
> >> >
> >> > Thanks for your help guys.
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > View this message in context:
> >> >
> http://monotouch.2284126.n4.nabble.com/iOS-6-ABAddressBook-RequestAccess-example-tp4657314.html
> >> > Sent from the MonoTouch mailing list archive at Nabble.com.
> >> > ___
> >> > MonoTouch mailing list
> >> > [hidden email]
> >> > http://lists.ximian.com/mailman/listinfo/monotouch
> >>
> >>
> >>
> >> --
> >> Nic Wise
> >> t.   >> target="_blank">+44 7788 592 806 | @fastchicken |
> >> http://www.linkedin.com/in/nicwise
> >>
> >> b. http://www.fastchicken.co.nz/
> >>
> >> mobileAgent (for FreeAgent): get your accounts in your pocket.
> >> http://goo.gl/IuBU
> >> Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
> >> Earnest: Self-employed? Track your business expenses and income.
> >> http://earnestapp.com
> >> Nearest Bus: find when the next bus is coming to your stop.
> >> http://goo.gl/Vcz1p
> >> London Bike App: Find the nearest Boris Bike, and get riding!
> >> http://goo.g