forked from shaojiankui/JKCategories
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jakey
committed
Dec 14, 2016
1 parent
0b7030e
commit 89b64c2
Showing
15 changed files
with
189 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// UIWebView+JKWebStorage.h | ||
// JKCategories (https://github.com/shaojiankui/JKCategories) | ||
// | ||
// Created by Jakey on 2016/12/14. | ||
// Copyright © 2016年 www.skyfox.org. All rights reserved. | ||
// https://github.com/cprime/UIWebView-WebStorage | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIWebView (JKWebStorage) | ||
#pragma mark - Local Storage | ||
|
||
- (void)jk_setLocalStorageString:(NSString *)string forKey:(NSString *)key; | ||
|
||
- (NSString *)jk_localStorageStringForKey:(NSString *)key; | ||
|
||
- (void)jk_removeLocalStorageStringForKey:(NSString *)key; | ||
|
||
- (void)jk_clearLocalStorage; | ||
|
||
#pragma mark - Session Storage | ||
|
||
- (void)jk_setSessionStorageString:(NSString *)string forKey:(NSString *)key; | ||
|
||
- (NSString *)jk_sessionStorageStringForKey:(NSString *)key; | ||
|
||
- (void)jk_removeSessionStorageStringForKey:(NSString *)key; | ||
|
||
- (void)jk_clearSessionStorage; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// UIWebView+JKWebStorage.m | ||
// JKCategories (https://github.com/shaojiankui/JKCategories) | ||
// | ||
// Created by Jakey on 2016/12/14. | ||
// Copyright © 2016年 www.skyfox.org. All rights reserved. | ||
// | ||
|
||
#import "UIWebView+JKWebStorage.h" | ||
|
||
static NSString * const jk_kLocalStorageName = @"localStorage"; | ||
static NSString * const jk_kSessionStorageName = @"sessionStorage"; | ||
|
||
|
||
@implementation UIWebView (JKWebStorage) | ||
#pragma mark - Local Storage | ||
|
||
- (void)jk_setLocalStorageString:(NSString *)string forKey:(NSString *)key { | ||
[self jk_ip_setString:string forKey:key storage:jk_kLocalStorageName]; | ||
} | ||
|
||
- (NSString *)jk_localStorageStringForKey:(NSString *)key { | ||
return [self jk_ip_stringForKey:key storage:jk_kLocalStorageName]; | ||
} | ||
|
||
- (void)jk_removeLocalStorageStringForKey:(NSString *)key { | ||
[self jk_ip_removeStringForKey:key storage:jk_kLocalStorageName]; | ||
} | ||
|
||
- (void)jk_clearLocalStorage { | ||
[self jk_ip_clearWithStorage:jk_kLocalStorageName]; | ||
} | ||
|
||
#pragma mark - Session Storage | ||
|
||
- (void)jk_setSessionStorageString:(NSString *)string forKey:(NSString *)key { | ||
[self jk_ip_setString:string forKey:key storage:jk_kSessionStorageName]; | ||
} | ||
|
||
- (NSString *)jk_sessionStorageStringForKey:(NSString *)key { | ||
return [self jk_ip_stringForKey:key storage:jk_kSessionStorageName]; | ||
} | ||
|
||
- (void)jk_removeSessionStorageStringForKey:(NSString *)key { | ||
[self jk_ip_removeStringForKey:key storage:jk_kSessionStorageName]; | ||
} | ||
|
||
- (void)jk_clearSessionStorage { | ||
[self jk_ip_clearWithStorage:jk_kSessionStorageName]; | ||
} | ||
|
||
#pragma mark - Helpers | ||
|
||
- (void)jk_ip_setString:(NSString *)string forKey:(NSString *)key storage:(NSString *)storage { | ||
[self stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"%@.setItem('%@', '%@');", storage, key, string]]; | ||
} | ||
|
||
- (NSString *)jk_ip_stringForKey:(NSString *)key storage:(NSString *)storage { | ||
return [self stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"%@.getItem('%@');", storage, key]]; | ||
} | ||
|
||
- (void)jk_ip_removeStringForKey:(NSString *)key storage:(NSString *)storage { | ||
[self stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"%@.removeItem('%@');", storage, key]]; | ||
} | ||
|
||
- (void)jk_ip_clearWithStorage:(NSString *)storage { | ||
[self stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"%@.clear();", storage]]; | ||
} | ||
@end |