Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed sharing to Snikket #56

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions Snikket - Share/AccountsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Snikket - Share/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Snikket - Share/Snikket - Share.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)org.snikket.ios.Share</string>
<string>$(AppIdentifierPrefix)org.snikket.ios</string>
</array>
</dict>
</plist>