     if (url.scheme != kOTPAuthScheme) { return nil }
 
     var queryDictionary = Dictionary<String, String>()
-    if let queryItems = NSURLComponents(URL: url, resolvingAgainstBaseURL: false)?.queryItems as? [NSURLQueryItem] {
+    if let queryItems = NSURLComponents(URL: url, resolvingAgainstBaseURL: false)?.queryItems {
         for item in queryItems {
             queryDictionary[item.name] = item.value
         }

    if let factor = parse(url.host, with: factorParser, defaultTo: nil) {
        if let secret = parse(queryDictionary[kQuerySecretKey], with: { MF_Base32Codec.dataFromBase32String($0) }, overrideWith: externalSecret) {
            if let algorithm = parse(queryDictionary[kQueryAlgorithmKey], with: algorithmFromString, defaultTo: Generator.defaultAlgorithm) {
                if let digits = parse(queryDictionary[kQueryDigitsKey], with: { $0.toInt() }, defaultTo: Generator.defaultDigits) {
                    if let core = Generator(factor: factor, secret: secret, algorithm: algorithm, digits: digits) {

                        var name = Token.defaultName
                        if let path = url.path {
                            if count(path) > 1 {
                                name = path.substringFromIndex(path.startIndex.successor()) // Skip the leading "/"
                            }
                        }

                        }
                        // If the name is prefixed by the issuer string, trim the name
                        if let prefixRange = name.rangeOfString(issuer) {
                            if (prefixRange.startIndex == issuer.startIndex) && (issuer.characters.count < name.characters.count) && (name[prefixRange.endIndex] == ":") {
                                name = name.substringFromIndex(prefixRange.endIndex.successor()).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
                            }
                        }
