<commit_before>module AddressBook
  module_function

  def address_book
    if UIDevice.currentDevice.systemVersion >= '6'
      ios6_create
    else
      ios5_create
    end
  end

  def ios6_create
    error = nil
    address_book = ABAddressBookCreateWithOptions(nil, error)
    request_authorization unless authorized?
    address_book
  end

  def ios5_create
    ABAddressBookCreate()
  end

  def request_authorization(&block)
    synchronous = !!block
    access_callback = lambda { |granted, error|
      # not sure what to do with error ... so we're ignoring it
      @address_book_access_granted = granted
      block.call(@address_book_access_granted) unless block.nil?
    }

    ABAddressBookRequestAccessWithCompletion address_book, access_callback
    if synchronous
      # Wait on the asynchronous callback before returning.
      while @address_book_access_granted.nil? do
        sleep 0.1
      end<commit_msg>Fix call to AddressBook.address_book recusively when request access on iOS 6<commit_after>module AddressBook
  module_function

  def address_book
    if UIDevice.currentDevice.systemVersion >= '6'
      ios6_create
    else
      ios5_create
    end
  end

  def ios6_create
    error = nil
    @address_book = ABAddressBookCreateWithOptions(nil, error)
    request_authorization unless authorized?
    @address_book
  end

  def ios5_create
    ABAddressBookCreate()
  end

  def request_authorization(&block)
    synchronous = !!block
    access_callback = lambda { |granted, error|
      # not sure what to do with error ... so we're ignoring it
      @address_book_access_granted = granted
      block.call(@address_book_access_granted) unless block.nil?
    }

    ABAddressBookRequestAccessWithCompletion @address_book, access_callback
    if synchronous
      # Wait on the asynchronous callback before returning.
      while @address_book_access_granted.nil? do
        sleep 0.1
      end
{'fraction_non_alphanumeric': 0.05284974093264249, 'fraction_numerical': 0.007772020725388601, 'mean_word_length': 3.27212389380531, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4588714', 'n_tokens_mistral': 574, 'n_tokens_neox': 550, 'n_words': 151}