2 // EditItemViewController.m
5 // Created by john on 10/24/12.
9 #import "EditItemViewController.h"
10 #import "MyKeychain.h"
11 //#import <regressions/SOSRegressionUtilities.h>
12 //#import <SOSCircle/Regressions/SOSRegressionUtilities.h>
13 #import <CKBridge/SOSCloudKeychainClient.h>
14 #import <CKBridge/SOSCloudKeychainConstants.h>
15 #include "utilities.h"
17 static const CFStringRef kAddItemKeyY = CFSTR("AddItem");
20 @interface EditItemViewController ()
24 @implementation EditItemViewController
26 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
28 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
30 // Custom initialization
38 // Do any additional setup after loading the view.
39 NSLog(@"_itemDetailModel: %@", _itemDetailModel);
41 dgroup = dispatch_group_create();
42 xpc_queue = dispatch_queue_create("EditItemViewController", DISPATCH_QUEUE_CONCURRENT);
43 _itemName.text = [_itemDetailModel objectForKey:(__bridge id)(kSecAttrService)];
44 _itemAccount.text = [_itemDetailModel objectForKey:(__bridge id)(kSecAttrAccount)];
45 // _itemPassword.text = @"TODO";//[_itemDetailModel objectForKey:(__bridge id)(kSecValueData)];
46 NSData *pwdData = [_itemDetailModel objectForKey:(__bridge id)(kSecValueData)];
49 NSString *pwd = [[NSString alloc] initWithData:pwdData encoding:NSUTF8StringEncoding];
50 _itemPassword.text = pwd;
53 _itemPassword.text = @"";
57 - (void)didReceiveMemoryWarning
59 [super didReceiveMemoryWarning];
60 // Dispose of any resources that can be recreated.
63 - (void)postToCloud:(NSDictionary *)kcitem
65 CFErrorRef error = NULL;
66 testPutObjectInCloud(kAddItemKeyY, (__bridge CFTypeRef)(kcitem), &error, dgroup, xpc_queue);
67 NSLog(@"NOT IMPLEMENTED: Sent new item to cloud: %@", kcitem);
70 - (IBAction)handlePasswordEditDone:(id)sender
72 NSLog(@"handlePasswordEditDone");
74 NSMutableDictionary *newItem = [NSMutableDictionary dictionaryWithCapacity:0];
75 [newItem setObject:[_itemPassword text] forKey:kItemPasswordKey];
76 [newItem setObject:[_itemAccount text] forKey:kItemAccountKey];
77 [newItem setObject:[_itemName text] forKey:kItemNameKey];
79 [[MyKeychain sharedInstance] setItem:newItem];
80 [self postToCloud:newItem];
84 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
86 NSLog(@"prepareForSegue EditDone");
87 if ([[segue identifier] isEqualToString:@"EditDone"])
89 NSLog(@"seque EditDone");
90 [self handlePasswordEditDone:NULL];