title: Swift: Exception when requesting access to Facebook
body: <p>After updating to XCode 8, Swift 3, and iOS 10, I've begun to get the following error when requesting permission to access Facebook accounts:</p>
  
  <blockquote>
    <p>*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Access options are not
    permitted for this account type. The options argument must be nil.'</p>
  </blockquote>
  
  <p>I've found three mentions of this error on SO:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/16453164/access-options-are-not-permitted-for-this-account-type-the-options-argument-mus">Access options are not permitted for this account type. The options argument must be nil.;</a></li>
  <li><a href="https://stackoverflow.com/questions/23732342/facebook-sdk-login-crash">Facebook SDK login crash</a></li>
  <li><a href="https://stackoverflow.com/questions/13320624/nsinvalidargumentexception-thrown-from-acaccountstore-when-calling-fbsession-op">NSInvalidArgumentException thrown from ACAccountStore when calling [FBSession openActiveSessionWithPermissions...] on iOS 6.0 and iOS 6.0.1</a></li>
  </ol>
  
  <p>The first two have no answers; the last suggests checking that the value returned from <a href="https://developer.apple.com/reference/accounts/acaccountstore/1493967-accounttype" rel="nofollow noreferrer"><code>accountType(withAccountTypeIdentifier ...)</code></a> isn't <code>nil</code>, which I was already doing.</p>
  
  <p>As mentioned elsewhere, this error is inconsistent with the <a href="https://developer.apple.com/reference/accounts/acaccountstore/1493964-requestaccesstoaccounts" rel="nofollow noreferrer">documentation</a>, which states that Facebook requires an options dictionary.</p>
  
  <p>Here is a small example which reproduces the problem and makes a big show of error checking everything I could think to error check:</p>
  
  <pre><code>import UIKit
  import Social
  import Accounts
  
  class DVSocialTestViewController: UIViewController {
  
      let localURL =  URL(string: "fb://")
      let serviceType = SLServiceTypeFacebook
      let accountID = ACAccountTypeIdentifierFacebook
      var accountType: ACAccountType? {
          return ACAccountStore().accountType(withAccountTypeIdentifier: self.accountID)
      }
      var accounts: [Any]? {
          guard let ac = self.accountType else { return nil }
          return ACAccountStore().accounts(with: ac)
      }
      static let appID = "MyAppID"
      let basicOptions =
          [ACFacebookAppIdKey: DVSocialTestViewController.appID,
           ACFacebookPermissionsKey: ["basic_info"],
           ACFacebookAudienceKey: ACFacebookAudienceFriends] as [AnyHashable: Any]
      let publishOptions =
          [ACFacebookAppIdKey:DVSocialTestViewController.appID,
           ACFacebookPermissionsKey:["publish_actions"],
           ACFacebookAudienceKey:ACFacebookAudienceFriends] as [AnyHashable: Any]
  
      var applicationIsInstalled: Bool {
          guard let url = self.localURL else {
              return false
          }
          return UIApplication.shared.canOpenURL(url)
      }
  
      var serviceIsAvailable: Bool {
          return SLComposeViewController.isAvailable(forServiceType: self.serviceType)
      }
  
      var userIsLoggedIn: Bool {
          guard let ac = self.accounts, ac.count &gt; 0 else {
              NSLog("\(self.accounts)")
              return false
          }
          return true
      }
  
      func requestPermissionsForAccountType(_ type: ACAccountType) {
  
          ACAccountStore().requestAccessToAccounts(with: type, options: self.basicOptions) {
              (success: Bool, error: Error?) -&gt; Void in
              if !success {
                  NSLog("\(error)")
                  return
              }
  
              ACAccountStore().requestAccessToAccounts(with: type, options: self.publishOptions) {
                  (success: Bool, error: Error?) -&gt; Void in
                  if !success {
                      NSLog("\(error)")
                      return
                  }
              }
  
          }
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          guard self.applicationIsInstalled else {
              NSLog("FB Application is not installed.")
              return
          }
  
          guard self.serviceIsAvailable else {
              NSLog("FB Service is unavailable.")
              return
          }
  
          guard self.userIsLoggedIn else {
              NSLog("User is not logged into FB.")
              return
          }
  
          guard let AT = self.accountType else {
              NSLog("No accounts.")
              return
          }
  
          self.requestPermissionsForAccountType(AT)
  
      }
  }
  </code></pre>
  
  <p>Has anyone run into this?  Any suggestions about what I'm missing?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>There are few reasons why I feel my question is different from the proposed duplicate.</p>
  
  <ol>
  <li>I'm not using the Facebook SDK.</li>
  <li>This is not a "rare case"--it consistently happens with this example every time I run it.</li>
  <li>This specifically began happening upon updating to XCode 8, Swift 3, and iOS 10 from the preceding versions.</li>
  <li>As stated above, the only answer to the other question (which I admit is not accepted) does <em>not</em> solve my problem.</li>
  <li>I've provided a complete, minimal example, which the other question does not.</li>
  </ol>