From 3459cd7b586f986afa8ff9940b12aa4f312fd1b1 Mon Sep 17 00:00:00 2001 From: Mehrooz Khan Date: Sun, 22 Aug 2021 21:27:09 +0500 Subject: [PATCH] - Fixed Sharing To Snikket --- .../AccountsTableViewController.swift | 42 ++++++++++--------- Snikket - Share/ShareViewController.swift | 4 +- Snikket - Share/Snikket - Share.entitlements | 2 +- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Snikket - Share/AccountsTableViewController.swift b/Snikket - Share/AccountsTableViewController.swift index dedc763d..5e5c5091 100644 --- a/Snikket - Share/AccountsTableViewController.swift +++ b/Snikket - Share/AccountsTableViewController.swift @@ -30,35 +30,39 @@ class AccountsTableViewController: UITableViewController { var selected: String? = nil; override func viewDidLoad() { - accounts = getAccounts(); - super.viewDidLoad(); - //tableView.register(AccountTableViewCell.self, forCellReuseIdentifier: "accountTableViewCell"); + super.viewDidLoad() + + accounts = getAccounts() + self.tableView.reloadData() } func getAccounts() -> [String] { var accounts = [String](); - let query = [ String(kSecClass) : kSecClassGenericPassword, String(kSecMatchLimit) : kSecMatchLimitAll, String(kSecReturnAttributes) : kCFBooleanTrue as Any, String(kSecAttrService) : "xmpp" ] as [String : Any]; - var result:AnyObject?; + let query = [ String(kSecClass) : kSecClassGenericPassword, + String(kSecMatchLimit) : kSecMatchLimitAll, + String(kSecReturnAttributes) : kCFBooleanTrue!, + String(kSecAttrService) : "xmpp" as NSObject] as [String : Any] + + var result:CFTypeRef?; - let lastResultCode: OSStatus = withUnsafeMutablePointer(to: &result) { - SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0)); + guard SecItemCopyMatching(query as CFDictionary, &result) == noErr else { + return [] } - if lastResultCode == noErr { - if let results = result as? [[String:NSObject]] { - for r in results { - let name = r[String(kSecAttrAccount)] as! String; - if let data = r[String(kSecAttrGeneric)] as? NSData { - let dict = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as? [String:AnyObject]; - if dict!["active"] as? Bool ?? false { - accounts.append(name); - } - } + if let results = result as? [[String:NSObject]] { + print(results) + for r in results { + let name = r[String(kSecAttrAccount)] as! String; + if let data = r[String(kSecAttrGeneric)] as? NSData { + let dict = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as? [String:AnyObject]; + accounts.append(name) +// if dict!["active"] as? Bool ?? false { +// accounts.append(name) +// } } } - } - return accounts; + return accounts } override func numberOfSections(in tableView: UITableView) -> Int { diff --git a/Snikket - Share/ShareViewController.swift b/Snikket - Share/ShareViewController.swift index 2b576329..86c404a5 100644 --- a/Snikket - Share/ShareViewController.swift +++ b/Snikket - Share/ShareViewController.swift @@ -106,8 +106,8 @@ class ShareViewController: SLComposeServiceViewController { override func didSelectPost() { if let provider = (self.extensionContext!.inputItems.first as? NSExtensionItem)?.attachments?.first { - if provider.hasItemConformingToTypeIdentifier(kUTTypeFileURL as String) { - provider.loadItem(forTypeIdentifier: kUTTypeFileURL as String, options: nil, completionHandler: { (item, error) in + if provider.hasItemConformingToTypeIdentifier(kUTTypeData as String) { + provider.loadItem(forTypeIdentifier: kUTTypeData as String, options: nil, completionHandler: { (item, error) in if let localUrl = item as? URL { let uti = try? localUrl.resourceValues(forKeys: [.typeIdentifierKey]).typeIdentifier; let mimeType = uti != nil ? (UTTypeCopyPreferredTagWithClass(uti! as CFString, kUTTagClassMIMEType)?.takeRetainedValue() as String?) : nil; diff --git a/Snikket - Share/Snikket - Share.entitlements b/Snikket - Share/Snikket - Share.entitlements index 9f9894d9..7736c08f 100644 --- a/Snikket - Share/Snikket - Share.entitlements +++ b/Snikket - Share/Snikket - Share.entitlements @@ -9,7 +9,7 @@ keychain-access-groups - $(AppIdentifierPrefix)org.snikket.ios.Share + $(AppIdentifierPrefix)org.snikket.ios