我正在开发基于Siri的支付系统应用程序。我实施了Siri及其工作正常。但我以静态方式添加联系人。但我的要求是,我将从我的服务器获取联系,而不是将其保存在我的扩展中。请建议我如何做到这一点。 我正在分享一些代码片段。 我的AppDelegate.swift
import UIKit
import Payment
import Intents
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Register names of contacts that may not be in the user's address book.
let contactNames = Contact.sampleContacts.map { $0.formattedName }
INVocabulary.shared().setVocabularyStrings(NSOrderedSet(array: contactNames), of: .contactName)
// Override point for customization after application launch.
return true
}
支付框架内的我的联系人类
import Intents
public struct Contact {
private static let nameFormatter = PersonNameComponentsFormatter()
public let nameComponents: PersonNameComponents
public let emailAddress: String
public var formattedName: String {
return Contact.nameFormatter.string(from: nameComponents)
}
public init(givenName: String?, familyName: String?, emailAddress: String) {
var nameComponents = PersonNameComponents()
nameComponents.givenName = givenName
nameComponents.familyName = familyName
self.nameComponents = nameComponents
self.emailAddress = emailAddress
}
}
public extension Contact {
static let sampleContacts = [
Contact(givenName: "Anne", familyName: "Johnson", emailAddress: "anne.johnson@example.com"),
Contact(givenName: "Maria", familyName: "Ruiz", emailAddress: "maria.ruiz@example.com"),
Contact(givenName: "Mei", familyName: "Chen", emailAddress: "mei.chen@example.com"),
Contact(givenName: "Gita", familyName: "Kumar", emailAddress: "gita.kumar@example.com"),
Contact(givenName: "Bill", familyName: "James", emailAddress: "bill.james@example.com"),
Contact(givenName: "Tom", familyName: "Clark", emailAddress: "tom.clark@example.com"),
Contact(givenName: "Juan", familyName: "Chavez", emailAddress: "juan.chavez@example.com"),
Contact(givenName: "Ravi", familyName: "Patel", emailAddress: "ravi.patel@example.com"),
]
}
我无法从AppDelgate设置联系人。请建议我。