mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-28 19:05:49 +00:00
45 lines
2.4 KiB
Swift
45 lines
2.4 KiB
Swift
import Foundation
|
|
import SwiftSignalKit
|
|
import TelegramCore
|
|
import Display
|
|
import DeviceAccess
|
|
import AccountContext
|
|
import AlertUI
|
|
import PresentationDataUtils
|
|
import PeerInfoUI
|
|
import ShareController
|
|
|
|
func openAddContactImpl(context: AccountContext, firstName: String = "", lastName: String = "", phoneNumber: String, label: String = "_$!<Mobile>!$_", present: @escaping (ViewController, Any?) -> Void, pushController: @escaping (ViewController) -> Void, completed: @escaping () -> Void = {}) {
|
|
let _ = (DeviceAccess.authorizationStatus(subject: .contacts)
|
|
|> take(1)
|
|
|> deliverOnMainQueue).startStandalone(next: { value in
|
|
switch value {
|
|
case .allowed:
|
|
let controller = context.sharedContext.makeNewContactScreen(
|
|
context: context,
|
|
peer: nil,
|
|
phoneNumber: phoneNumber,
|
|
shareViaException: false,
|
|
completion: { peer, stableId, contactData in
|
|
if let peer = peer {
|
|
if let infoController = context.sharedContext.makePeerInfoController(context: context, updatedPresentationData: nil, peer: peer._asPeer(), mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) {
|
|
pushController(infoController)
|
|
}
|
|
} else if let stableId, let contactData {
|
|
pushController(deviceContactInfoController(context: ShareControllerAppAccountContext(context: context), environment: ShareControllerAppEnvironment(sharedContext: context.sharedContext), subject: .vcard(nil, stableId, contactData), completed: nil, cancelled: nil))
|
|
}
|
|
completed()
|
|
}
|
|
)
|
|
pushController(controller)
|
|
case .notDetermined:
|
|
DeviceAccess.authorizeAccess(to: .contacts)
|
|
default:
|
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
|
present(textAlertController(context: context, title: presentationData.strings.AccessDenied_Title, text: presentationData.strings.Contacts_AccessDeniedError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_NotNow, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.AccessDenied_Settings, action: {
|
|
context.sharedContext.applicationBindings.openSettings()
|
|
})]), nil)
|
|
}
|
|
})
|
|
}
|