- Fix AccessToken Save, SharedInstance
- Fix crash in removeObserver PNObject
This commit is contained in:
1 parent
41c856b3c9
commit
c23b1e0e38
8 files changed
+187
-107
No files matched your search
@@ -20,9 +20,16 @@ typedef NS_ENUM(NSInteger, TokenType) {
|
||||
*
|
||||
* @return singleton
|
||||
*/
|
||||
+ (instancetype _Nonnull) currentUser;
|
||||
+ (instancetype _Nonnull) currentAccessToken;
|
||||
|
||||
|
||||
/**
|
||||
* gets singleton object of current user session.
|
||||
*
|
||||
* @return singleton
|
||||
*/
|
||||
+ (instancetype _Nonnull) currentAccessTokenWithJSON:(NSDictionary *)JSON;
|
||||
|
||||
///--------------------------------------
|
||||
#pragma mark - PNAccessToken Properties
|
||||
///--------------------------------------
|
||||
|
||||
@@ -15,6 +15,81 @@
|
||||
|
||||
@implementation PNAccessToken
|
||||
|
||||
static PNAccessToken *SINGLETON = nil;
|
||||
|
||||
static bool isFirstAccess = YES;
|
||||
|
||||
#pragma mark - Public Method
|
||||
|
||||
+ (instancetype) currentAccessToken {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
isFirstAccess = NO;
|
||||
|
||||
SINGLETON = [[super allocWithZone:NULL] initForCurrentAccessTokenWithJSON:nil];
|
||||
});
|
||||
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
+ (instancetype _Nonnull) currentAccessTokenWithJSON:(NSDictionary *)JSON {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
isFirstAccess = NO;
|
||||
|
||||
SINGLETON = [[super allocWithZone:NULL] initForCurrentAccessTokenWithJSON:JSON];
|
||||
});
|
||||
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
|
||||
- (instancetype) initForCurrentAccessTokenWithJSON:(NSDictionary *)JSON {
|
||||
if(SINGLETON){
|
||||
return SINGLETON;
|
||||
}
|
||||
if (isFirstAccess) {
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
}
|
||||
NSDictionary *savedAccessToken;
|
||||
|
||||
if (JSON) {
|
||||
savedAccessToken = JSON;
|
||||
}
|
||||
else {
|
||||
savedAccessToken = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]];
|
||||
}
|
||||
|
||||
if (savedAccessToken) {
|
||||
self = [super initWithJSON:savedAccessToken];
|
||||
}
|
||||
else {
|
||||
self = [super init];
|
||||
}
|
||||
|
||||
if (self) {
|
||||
if (_tokenTypeString) {
|
||||
((void (^)())@{
|
||||
@"beaer" : ^{
|
||||
_tokenType = TokenTypeBearer;
|
||||
},
|
||||
@"basic" : ^{
|
||||
_tokenType = TokenTypeBasic;
|
||||
}
|
||||
}[_tokenTypeString] ?: ^{
|
||||
|
||||
})();
|
||||
}
|
||||
|
||||
if (_expiresIn) {
|
||||
_expirationDate = [[NSDate date] dateByAddingHours:[_expiresIn integerValue]];
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark PNObjectSubclassing Protocol
|
||||
|
||||
+ (NSDictionary *)objcetMapping {
|
||||
@@ -30,23 +105,7 @@
|
||||
}
|
||||
|
||||
- (instancetype) initWithJSON:(NSDictionary *)JSON {
|
||||
self = [super initWithJSON:JSON];
|
||||
|
||||
if (self) {
|
||||
((void (^)())@{
|
||||
@"beaer" : ^{
|
||||
_tokenType = TokenTypeBearer;
|
||||
},
|
||||
@"basic" : ^{
|
||||
_tokenType = TokenTypeBasic;
|
||||
}
|
||||
}[_tokenTypeString] ?: ^{
|
||||
|
||||
})();
|
||||
|
||||
_expirationDate = [[NSDate date] dateByAddingHours:[_expiresIn integerValue]];
|
||||
}
|
||||
return self;
|
||||
return [[self class] currentAccessTokenWithJSON:JSON];
|
||||
}
|
||||
|
||||
+ (NSString *)objectClassName {
|
||||
|
||||
Reference in new issue
Block a user