Closed jamonholmgren closed 12 years ago
Sorry I didn't have time to look at this. I think the async nature of it will feel weird to a client, but if that's what apple requires us to use we may not have a choice. I need to play with it today and will post some thoughts soon.
BTW - thanks for all your interest, ideas and pulls on this project :)
Certainly -- thanks for doing the initial difficult work of putting it together. I definitely need this! :)
Agreed on the async nature of it. If you have a better idea I'm definitely happy to adjust. The biggest issue is waiting for a user to approve access.
What do you think of this tweak to the API you suggested?
# returns true if authorized and false otherwise
AddressBook.authorized?
# returns one of [:not_determined, :restricted, :denied, :authorized]
AddressBook.authorization_status
# Ask user for authorization if app is not already authorized. There are 2 ways to use this method
# 1. returns immediately. Block is called later with status one of the authorization_status values
AddressBook.request_authorization do |status|
# do something
end
# 2. it blocks until knowing the status and returns status
AddressBook.request_authorization(true)
The idea is that an app could wrap every call in request_authorization
but it doesn't have to. I'm hoping to figure out how to implement option 2 so you could request_authorization at the right time in your app and then make simple calls like
people = AddressBook::Person.all
# rest of code
instead of the more complicated version
AddressBook.request_authorization do |status|
people = AddressBook::Person.all if status
# do something with people
end
# rest of code, but you don't have access to people here
I like the idea, but I don't know if it would work to block until knowing the status. The alert would need to be displayed and I'm not sure if the main execution thread freezing would prevent this from happening. I guess we'll have to test it. :)
I believe I have this working in https://github.com/alexrothenberg/motion-addressbook/tree/authorization but I don't have an IOS6 device yet and the simulator isn't ever asking me for authorization.
Reactions?
It looks good. Like I said, might not work with synchronous call, but we'll just have to test that. I'd merge it in and see what happens. :)
Your code appears to work for iOS 6. There's an iOS 5 issue now, but I'll open a new issue.
Any feedback on this?