-
Notifications
You must be signed in to change notification settings - Fork 0
/
PLAccountStore.m
105 lines (90 loc) · 2.93 KB
/
PLAccountStore.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// PLAccountStore.m
// Plate
//
// Created by emileleon on 2/25/14.
// Copyright (c) 2014 Plate SF. All rights reserved.
//
#import "PLAccountStore.h"
#import "PLAccount.h"
@implementation PLAccountStore
- (BOOL)login:(PLAccount *)pAccount
{
// NSString *path = [self accountArchivePath];
// [NSKeyedArchiver archiveRootObject:pAccount toFile:path];
// account = pAccount;
// [[NSNotificationCenter defaultCenter] postNotificationName:@"UserLoggedIn" object:self];
return true;
}
- (PLAccount *)getAccount
{
return account;
}
- (id)init {
self = [super init];
// if (self) {
// NSString *path = [self accountArchivePath];
// account = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
// if (!account) {
// account = nil;
// }
// }
return self;
}
#pragma Singleton setup
+ (id)allocWithZone:(struct _NSZone *)zone
{
return [self sharedStore];
}
+ (PLAccountStore *)sharedStore
{
static PLAccountStore *sharedStore = nil;
if (!sharedStore) {
sharedStore = [[super allocWithZone:nil] init];
}
return sharedStore;
}
- (NSString *)accountArchivePath
{
NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [documentDirectories objectAtIndex:0];
return [documentDirectory stringByAppendingPathComponent:@"account.archive"];
}
//- (void) logout
//{
// [[PLPlateStore sharedStore] login:account forBlock:^(PLAccount *accountResult, NSError *err) {
//
// if (!err) {
// [[NSNotificationCenter defaultCenter] postNotificationName:@"UserLoggedIn" object:self];
// NSString *path = [self accountArchivePath];
// [NSKeyedArchiver archiveRootObject:accountResult toFile:path];
// [[self delegate] userLoggedIn];
// } else {
// UIAlertView *av =[[UIAlertView alloc]
// initWithTitle:@"Error"
// message:[err localizedDescription]
// delegate:nil
// cancelButtonTitle:@"OK"
// otherButtonTitles:nil];
// [av show];
// }
// }];
//}
- (BOOL)logout2
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
BOOL success = [fileManager removeItemAtPath:[self accountArchivePath] error:&error];
if (success) {
// UIAlertView *removeSuccessFullAlert=[[UIAlertView alloc]initWithTitle:@"Logged Out" message:@"Successfully logged out" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
// [removeSuccessFullAlert show];
account = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:@"UserLoggedOut" object:self];
}
else
{
NSLog(@"Could not logout; can't delete file -:%@ ",[error localizedDescription]);
}
return success;
}
@end