![]() |
Ignite Tools
|
00001 /* 00002 Copyright 2009-2011 Urban Airship Inc. All rights reserved. 00003 00004 Redistribution and use in source and binary forms, with or without 00005 modification, are permitted provided that the following conditions are met: 00006 00007 1. Redistributions of source code must retain the above copyright notice, this 00008 list of conditions and the following disclaimer. 00009 00010 2. Redistributions in binaryform must reproduce the above copyright notice, 00011 this list of conditions and the following disclaimer in the documentation 00012 and/or other materials provided withthe distribution. 00013 00014 THIS SOFTWARE IS PROVIDED BY THE URBAN AIRSHIP INC ``AS IS'' AND ANY EXPRESS OR 00015 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00016 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 00017 EVENT SHALL URBAN AIRSHIP INC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 00018 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00019 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00020 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00021 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00022 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00023 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 */ 00025 00026 #import <UIKit/UIKit.h> 00027 00028 // ALog always displays output regardless of the UADEBUG setting 00029 //#define UA_ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); 00030 #define UA_BLog(fmt, ...) \ 00031 do { \ 00032 if (logging) { \ 00033 NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); \ 00034 } \ 00035 } while(0) 00036 00037 // UADEBUG set in debug build setting's "Other C flags", as -DUADEBUG 00038 //#ifdef UADEBUG 00039 //#define UA_DLog UA_ALog 00040 //#else 00041 #define UA_DLog UA_BLog 00042 extern BOOL logging; // Default is false 00043 //#endif 00044 00045 #define UALOG UA_DLog 00046 00047 // constants 00048 #define kAirshipProductionServer @"https://go.urbanairship.com" 00049 00050 // path 00051 #define kPendingProductsFile [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, \ 00052 NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString: @"/ua/pendingProducts.history"] 00053 00054 #define kDownloadHistoryFile [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, \ 00055 NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString: @"/ua/download.history"] 00056 00057 #define kReceiptHistoryFile [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, \ 00058 NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString: @"/ua/receipt.history"] 00059 00060 #define kUADirectory [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, \ 00061 NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString: @"/ua/"] 00062 00063 #define kUAOldDirectory [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, \ 00064 NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString: @"/ua/"] 00065 00066 #define kUADownloadDirectory [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, \ 00067 NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString: @"/ua/downloads/"] 00068 00069 #define kUAOldDownloadDirectory [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, \ 00070 NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString: @"/"] 00071 00072 // color 00073 #define RGBA(r,g,b,a) [UIColor colorWithRed: r/255.0f green: g/255.0f \ 00074 blue: b/255.0f alpha: a] 00075 00076 #define BG_RGBA(r,g,b,a) CGContextSetRGBFillColor(context, r/255.0f, \ 00077 g/255.0f, b/255.0f, a) 00078 00079 #define kUpdateFGColor RGBA(255, 131, 48, 1) 00080 #define kUpdateBGColor RGBA(255, 228, 201, 1) 00081 00082 #define kInstalledFGColor RGBA(60, 150, 60, 1) 00083 #define kInstalledBGColor RGBA(185, 220, 185, 1) 00084 00085 #define kDownloadingFGColor RGBA(45, 138, 193, 1) 00086 #define kDownloadingBGColor RGBA(173, 213, 237, 1) 00087 00088 #define kPriceFGColor [UIColor darkTextColor] 00089 #define kPriceBorderColor RGBA(185, 185, 185, 1) 00090 #define kPriceBGColor RGBA(217, 217, 217, 1) 00091 00092 // tag 00093 #define __UA_DEPRECATED __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_3_0,__IPHONE_3_0) 00094 00095 // code block 00096 #define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; } 00097 00098 #ifdef _UA_VERSION 00099 #define UA_VERSION @ _UA_VERSION 00100 #else 00101 #define UA_VERSION @ "1.0.7" 00102 #endif 00103 00104 #define UA_VERSION_INTERFACE(CLASSNAME) \ 00105 @interface CLASSNAME : NSObject \ 00106 + (NSString *)get; \ 00107 @end 00108 00109 00110 #define UA_VERSION_IMPLEMENTATION(CLASSNAME, VERSION_STR) \ 00111 @implementation CLASSNAME \ 00112 + (NSString *)get { \ 00113 return VERSION_STR; \ 00114 } \ 00115 @end 00116 00117 00118 #define SINGLETON_INTERFACE(CLASSNAME) \ 00119 + (CLASSNAME*)shared;\ 00120 - (void)forceRelease; 00121 00122 00123 #define SINGLETON_IMPLEMENTATION(CLASSNAME) \ 00124 \ 00125 static CLASSNAME* g_shared##CLASSNAME = nil; \ 00126 \ 00127 + (CLASSNAME*)shared \ 00128 { \ 00129 if (g_shared##CLASSNAME != nil) { \ 00130 return g_shared##CLASSNAME; \ 00131 } \ 00132 \ 00133 @synchronized(self) { \ 00134 if (g_shared##CLASSNAME == nil) { \ 00135 g_shared##CLASSNAME = [[self alloc] init]; \ 00136 } \ 00137 } \ 00138 \ 00139 return g_shared##CLASSNAME; \ 00140 } \ 00141 \ 00142 + (id)allocWithZone:(NSZone*)zone \ 00143 { \ 00144 @synchronized(self) { \ 00145 if (g_shared##CLASSNAME == nil) { \ 00146 g_shared##CLASSNAME = [super allocWithZone:zone]; \ 00147 return g_shared##CLASSNAME; \ 00148 } \ 00149 } \ 00150 NSAssert(NO, @ "[" #CLASSNAME \ 00151 " alloc] explicitly called on singleton class."); \ 00152 return nil; \ 00153 } \ 00154 \ 00155 - (id)copyWithZone:(NSZone*)zone \ 00156 { \ 00157 return self; \ 00158 } \ 00159 \ 00160 - (id)retain \ 00161 { \ 00162 return self; \ 00163 } \ 00164 \ 00165 - (oneway void)release \ 00166 { \ 00167 } \ 00168 \ 00169 - (void)forceRelease { \ 00170 UALOG(@"Force release "#CLASSNAME""); \ 00171 @synchronized(self) { \ 00172 if (g_shared##CLASSNAME != nil) { \ 00173 g_shared##CLASSNAME = nil; \ 00174 } \ 00175 } \ 00176 [super release]; \ 00177 } \ 00178 \ 00179 - (id)autorelease \ 00180 { \ 00181 return self; \ 00182 } 00183 00184 00185 #ifndef kCFCoreFoundationVersionNumber_iPhoneOS_4_0 00186 #define kCFCoreFoundationVersionNumber_iPhoneOS_4_0 550.32 00187 #endif 00188 00189 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000 00190 #define IF_IOS4_OR_GREATER(...) \ 00191 if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_4_0) \ 00192 { \ 00193 __VA_ARGS__ \ 00194 } 00195 #else 00196 #define IF_IOS4_OR_GREATER(...) 00197 #endif 00198