check ABAddressBookGetAuthorizationStatus before showFriendsInContacts

This commit is contained in:
nixzhu
2015-06-01 16:17:56 +08:00
parent 41cd05b7d7
commit 85a2f368dd
@@ -7,6 +7,7 @@
//
import UIKit
import AddressBook
class AddFriendsViewController: UIViewController {
@@ -130,8 +131,40 @@ extension AddFriendsViewController: UITableViewDataSource, UITableViewDelegate {
switch indexPath.row {
case More.Contacts.rawValue:
performSegueWithIdentifier("showFriendsInContacts", sender: nil)
switch ABAddressBookGetAuthorizationStatus() {
case .NotDetermined:
YepAlert.confirmOrCancel(title: NSLocalizedString("Notice", comment: ""), message: NSLocalizedString("Yep need to read your Contacts to continue this operation.\nIs that OK?", comment: ""), confirmTitle: NSLocalizedString("OK", comment: ""), cancelTitle: NSLocalizedString("No now", comment: ""), inViewController: self, withConfirmAction: {
if let addressBook: ABAddressBook = ABAddressBookCreateWithOptions(nil, nil)?.takeRetainedValue() {
ABAddressBookRequestAccessWithCompletion(addressBook, { granted, error in
if granted {
dispatch_async(dispatch_get_main_queue()) {
self.performSegueWithIdentifier("showFriendsInContacts", sender: nil)
}
}
})
}
}, cancelAction: {
})
case .Authorized:
performSegueWithIdentifier("showFriendsInContacts", sender: nil)
case .Denied:
YepAlert.confirmOrCancel(title: NSLocalizedString("Sorry", comment: ""), message: NSLocalizedString("Yep can not read your Contacts!\nBut you can change it in iOS' Settings.\n", comment: ""), confirmTitle: NSLocalizedString("Change it now", comment: ""), cancelTitle: NSLocalizedString("Dismiss", comment: ""), inViewController: self, withConfirmAction: {
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
}, cancelAction: {
})
case .Restricted:
YepAlert.alertSorry(message: NSLocalizedString("Yep can not read your Contacts!", comment: ""), inViewController: self)
}
case More.FaceToFace.rawValue:
break