-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDUtilities.h
119 lines (102 loc) · 5.73 KB
/
PDUtilities.h
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// Utilities.h
// ios-common
//
// Created by Peter Denniss on 8/03/11.
// Copyright 2011 Go1 Pty Ltd. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonDigest.h>
#import <MapKit/MapKit.h>
#import <StoreKit/StoreKit.h>
#ifndef SITE_URL
#define SITE_URL @""
#endif
#define t(string) NSLocalizedString(string, nil)
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
# define DLog1(fmt, ...) {static __dlog1_once = true; if (__dlog1_once) { NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); __dlog1_once = false; } }
#else
# define DLog(...)
# define DLog1(...)
#endif
#define DLogC(is_active,fmt, ...) {if (is_active) { DLog(fmt, ##__VA_ARGS__); } }
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#ifdef UI_USER_INTERFACE_IDIOM
#define IS_IPAD() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define _IPHONESDK3_2
#else
#define IS_IPAD() (false)
#endif
#ifndef kStandardErrorDomain
#define kStandardErrorDomain @"1234"
#endif
typedef void (^PDUtilitiesIAPCompletionBlock)(SKRequest* request);
typedef void (^PDUtilitiesIAPFailureBlock)(NSError* error);
@interface PDUtilities : NSObject <UIAlertViewDelegate, SKRequestDelegate> {
int indicatorCount;
BOOL alertShowing;
NSMutableDictionary* alertTags;
PDUtilitiesIAPCompletionBlock refreshIAPCompletionBlock;
PDUtilitiesIAPFailureBlock refreshIAPFailureBlock;
}
#define kConnectionErrorTag 148194
// dynamic methods
- (void) showNetworkIndicator:(BOOL)on;
- (void) changeNetworkIndicator;
- (void) showConnectionError; // only shows one alert at once so that connection errors don't stack up.
- (void) showAlertWithTitle:(NSString*)title message:(NSString*)message tag:(int)tag;
- (void) refreshIAPReceiptCompletion:(PDUtilitiesIAPCompletionBlock)completionBlock failure:(PDUtilitiesIAPFailureBlock)failureBlock;
// static methods
+ (PDUtilities*) sharedUtilities;
+ (NSString *) returnMD5Hash:(NSString*)concat;
+ (void)resizeFontForLabel:(UILabel*)aLabel maxSize:(int)maxSize minSize:(int)minSize;
+ (NSString*) getDocumentsDirectoryPath;
+ (NSString*) getFilePathForFileInDocumentsDirectory:(NSString*)filename;
+ (NSString*) sendRequestReturningStringToPath:(NSString*)path withArgs:(NSDictionary*) args;
+ (NSString *)generateSHA256Hash:(NSString *)inputString usingKey:(NSString*)key;
+ (NSString*)stringWithHexBytes:(NSData *)theData;
+ (NSString *) genRandStringLength;
+ (void) showAlertWithTitle:(NSString*)title message:(NSString*)message;
+ (void) showConnectionError;
+ (UIColor *) colorWithHexString: (NSString *) stringToConvert;
+ (void) clearCookies;
+ (UIImage*)imageByScalingAndCroppingImage:(UIImage*)image forSize:(CGSize)targetSize;
+ (NSString*)getYoutubeEmbedCodeForVideoID:(NSString*)videoID size:(CGSize)size;
+ (BOOL) string:(NSString*)string1 containsString:(NSString*)substring;
+ (BOOL) isPortrait;
+ (NSString*) getPOSTMethodsStringFromDictionary:(NSDictionary*)dictionary;
+ (NSData*) sendRequestToPath:(NSString*)path withArgs:(NSDictionary*)args method:(NSString*)httpMethod;
+ (NSData*) sendRequestToURL:(NSString*)url withArgs:(NSDictionary*)args method:(NSString*)httpMethod returningResponse:(NSHTTPURLResponse**)response error:(NSError**)error;
+ (NSData*) sendRequestToURL:(NSString*)url withArgs:(NSDictionary*)args headers:(NSDictionary*)headers method:(NSString*)httpMethod returningResponse:(NSHTTPURLResponse**)response error:(NSError**)error;
+ (NSMutableURLRequest*) getURLRequestForURL:(NSString*)path args:(NSDictionary*)args method:(NSString*)httpMethod;
+ (NSMutableURLRequest*) getURLRequestForURL:(NSString*)url args:(NSDictionary*)args method:(NSString*)httpMethod useMultipart:(BOOL)multipart;
+ (NSString*) truncateString:(NSString*)string toLength:(int)length;
+ (NSString*) getLocalizedDateStringForDate:(NSDate*)date;
+ (void) showComingSoonAlert;
+ (NSString*)timeIntervalStringWithStartDate:(NSDate*)d1 withEndDate:(NSDate*)d2;
+ (int) convertFloatToEvenInt:(CGFloat)float_num;
+ (NSDictionary *)parseURLParams:(NSString *)query;
+ (void) centerView:(UIView *)view horizontallyInView:(UIView*)view2;
+ (void) centerView:(UIView *)view verticallyInView:(UIView*)view2;
+ (void) centerView:(UIView*)view inView:(UIView*)view2;
+ (CGRect) centerRect:(CGRect)rect inRect:(CGRect)parentRect;
+ (NSDictionary*) getArgsDictionaryFromPOSTMethodsString:(NSString*)string;
+ (NSString*) sendRequestReturningStringToPath:(NSString*)path withArgs:(NSDictionary*) args method:(NSString*)httpMethod;
+ (NSError*) errorWithCode:(int)code title:(NSString*)title message:(NSString*)message;
+ (UIImage*)circularScaleNCrop:(UIImage*)image andRect:(CGRect)rect;
+ (void) showAlertForError:(NSError*)error;
+ (void) addConstraintsForSubview:(UIView*)subView toFillSuperView:(UIView*)superView;
+ (void) addConstraintsForSubview:(UIView *)subView toFillSuperViewHorizontally:(UIView *)superView;
+ (void) addConstraintsForSubview:(UIView *)subView toFillSuperViewVertically:(UIView *)superView;
+ (void) addBottomConstraintForSubView:(UIView*)subView superView:(UIView*)superView;
+ (void) addLeadingConstraintForSubView:(UIView*)subView superView:(UIView*)superView;
+ (void) circularCrop:(UIView*)view;
+ (void) locationFromImagePickerInfo:(NSDictionary*)info completion:(void (^)(CLLocation* location))completionBlock;
+ (NSString*) addressStringFromPlacemark:(CLPlacemark*)placemark;
+ (void) addressStringFromLocation:(CLLocation*)location completion:(void (^)(NSString* address))completionBlock;
+ (NSString*) getDeviceName;
+ (UIImage*) resizeImage:(UIImage*)image toMaximumWidth:(CGFloat)maxWidth;
+ (NSString *)hmac:(NSString *)plaintext withKey:(NSString *)key;
@end