forked from SoCuul/SCInsta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManager.m
63 lines (49 loc) · 2.7 KB
/
Manager.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
#import "Manager.h"
#import "InstagramHeaders.h"
@implementation SCIManager
+ (BOOL)getPref:(NSString *)key {
if (!key) return false;
return [[NSUserDefaults standardUserDefaults] boolForKey:key];
}
+ (void)cleanCache {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableArray<NSError *> *deletionErrors = [NSMutableArray array];
// Temp folder
NSError *tempFolderError;
[fileManager removeItemAtURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] error:&tempFolderError];
if (tempFolderError) [deletionErrors addObject:tempFolderError];
// Analytics folder
NSError *analyticsFolderError;
NSString *analyticsFolder = [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Application Support/com.burbn.instagram/analytics"];
[fileManager removeItemAtURL:[[NSURL alloc] initFileURLWithPath:analyticsFolder] error:&analyticsFolderError];
if (analyticsFolderError) [deletionErrors addObject:analyticsFolderError];
// Caches folder
NSString *cachesFolder = [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Caches"];
NSArray *cachesFolderContents = [fileManager contentsOfDirectoryAtURL:[[NSURL alloc] initFileURLWithPath:cachesFolder] includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
for (NSURL *fileURL in cachesFolderContents) {
NSError *cacheItemDeletionError;
[fileManager removeItemAtURL:fileURL error:&cacheItemDeletionError];
if (cacheItemDeletionError) [deletionErrors addObject:cacheItemDeletionError];
}
// Log errors
if (deletionErrors.count > 1) {
for (NSError *error in deletionErrors) {
NSLog(@"[SCInsta] File Deletion Error: %@", error);
}
}
}
+ (void)showSaveVC:(id)item {
UIActivityViewController *acVC = [[UIActivityViewController alloc] initWithActivityItems:@[item] applicationActivities:nil];
if (is_iPad()) {
acVC.popoverPresentationController.sourceView = topMostController().view;
acVC.popoverPresentationController.sourceRect = CGRectMake(topMostController().view.bounds.size.width / 2.0, topMostController().view.bounds.size.height / 2.0, 1.0, 1.0);
}
[topMostController() presentViewController:acVC animated:true completion:nil];
}
+ (NSString *)getDownloadingPersent:(float)per {
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterPercentStyle];
NSNumber *number = [NSNumber numberWithFloat:per];
return [numberFormatter stringFromNumber:number];
}
@end