Enable JSON for App Store builds, but do not submit the UDID and don't evaluate the returned JSON.

This commit is contained in:
Thomas Dohmke 2011-12-05 15:41:20 +01:00
parent 9162b740e9
commit ec5178919f
2 changed files with 104 additions and 112 deletions

View File

@ -423,36 +423,31 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
NSLog(@"WARNING: Hockey.bundle is missing, make sure it is added!"); NSLog(@"WARNING: Hockey.bundle is missing, make sure it is added!");
} }
if (!isAppStoreEnvironment_) { [self loadAppCache_];
[self loadAppCache_]; [self startUsage];
[self startUsage]; [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(startManager)
[[NSNotificationCenter defaultCenter] addObserver:self name:BWHockeyNetworkBecomeReachable
selector:@selector(startManager) object:nil];
name:BWHockeyNetworkBecomeReachable
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(stopUsage) selector:@selector(stopUsage)
name:UIApplicationWillTerminateNotification name:UIApplicationWillTerminateNotification
object:nil]; object:nil];
}
} }
return self; return self;
} }
- (void)dealloc { - (void)dealloc {
if (!isAppStoreEnvironment_) { [[NSNotificationCenter defaultCenter] removeObserver:self name:BWHockeyNetworkBecomeReachable object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:BWHockeyNetworkBecomeReachable object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
BW_IF_IOS4_OR_GREATER(
BW_IF_IOS4_OR_GREATER( [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil]; )
)
}
self.delegate = nil; self.delegate = nil;
[urlConnection_ cancel]; [urlConnection_ cancel];
@ -540,6 +535,8 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
- (void)showCheckForUpdateAlert_ { - (void)showCheckForUpdateAlert_ {
if (isAppStoreEnvironment_) return;
if (!updateAlertShowing_) { if (!updateAlertShowing_) {
if ([self.app.mandatory boolValue] ) { if ([self.app.mandatory boolValue] ) {
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:BWHockeyLocalize(@"HockeyUpdateAvailable") UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:BWHockeyLocalize(@"HockeyUpdateAvailable")
@ -704,19 +701,19 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
#pragma mark RequestComments #pragma mark RequestComments
- (BOOL)shouldCheckForUpdates { - (BOOL)shouldCheckForUpdates {
if (isAppStoreEnvironment_) return NO;
BOOL checkForUpdate = NO; BOOL checkForUpdate = NO;
switch (self.updateSetting) { switch (self.updateSetting) {
case HockeyUpdateCheckStartup: case HockeyUpdateCheckStartup:
checkForUpdate = YES; checkForUpdate = YES;
break; break;
case HockeyUpdateCheckDaily: case HockeyUpdateCheckDaily: {
NSTimeInterval dateDiff = fabs([self.lastCheck timeIntervalSinceNow]); NSTimeInterval dateDiff = fabs([self.lastCheck timeIntervalSinceNow]);
if (dateDiff != 0) if (dateDiff != 0)
dateDiff = dateDiff / (60*60*24); dateDiff = dateDiff / (60*60*24);
checkForUpdate = (dateDiff >= 1); checkForUpdate = (dateDiff >= 1);
break; break;
}
case HockeyUpdateCheckManually: case HockeyUpdateCheckManually:
checkForUpdate = NO; checkForUpdate = NO;
break; break;
@ -731,7 +728,7 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
[parameter appendFormat:@"?format=json&authorize=yes&app_version=%@&udid=%@", [parameter appendFormat:@"?format=json&authorize=yes&app_version=%@&udid=%@",
[[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] bw_URLEncodedString], [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] bw_URLEncodedString],
[[self deviceIdentifier] bw_URLEncodedString] ([self isAppStoreEnvironment] ? @"appstore" : [[self deviceIdentifier] bw_URLEncodedString])
]; ];
// build request & send // build request & send
@ -798,7 +795,6 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
} }
- (void)checkForUpdate { - (void)checkForUpdate {
if (isAppStoreEnvironment_) return;
if (self.requireAuthorization) return; if (self.requireAuthorization) return;
if (self.isUpdateAvailable && [self.app.mandatory boolValue]) { if (self.isUpdateAvailable && [self.app.mandatory boolValue]) {
[self showCheckForUpdateAlert_]; [self showCheckForUpdateAlert_];
@ -808,7 +804,6 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
} }
- (void)checkForUpdateShowFeedback:(BOOL)feedback { - (void)checkForUpdateShowFeedback:(BOOL)feedback {
if (isAppStoreEnvironment_) return;
if (self.isCheckInProgress) return; if (self.isCheckInProgress) return;
showFeedback_ = feedback; showFeedback_ = feedback;
@ -823,7 +818,7 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
NSMutableString *parameter = [NSMutableString stringWithFormat:@"api/2/apps/%@?format=json&udid=%@", NSMutableString *parameter = [NSMutableString stringWithFormat:@"api/2/apps/%@?format=json&udid=%@",
[[self encodedAppIdentifier_] bw_URLEncodedString], [[self encodedAppIdentifier_] bw_URLEncodedString],
[[self deviceIdentifier] bw_URLEncodedString]]; ([self isAppStoreEnvironment] ? @"" : [[self deviceIdentifier] bw_URLEncodedString])];
// add additional statistics if user didn't disable flag // add additional statistics if user didn't disable flag
if ([self canSendUserData]) { if ([self canSendUserData]) {
@ -863,6 +858,8 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
} }
- (BOOL)initiateAppDownload { - (BOOL)initiateAppDownload {
if ([self isAppStoreEnvironment]) return NO;
if (!self.isUpdateAvailable) { if (!self.isUpdateAvailable) {
BWHockeyLog(@"Warning: No update available. Aborting."); BWHockeyLog(@"Warning: No update available. Aborting.");
return NO; return NO;
@ -925,8 +922,6 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
// begin the startup process // begin the startup process
- (void)startManager { - (void)startManager {
if (isAppStoreEnvironment_) return;
if (![self appVersionIsAuthorized]) { if (![self appVersionIsAuthorized]) {
if ([self authorizationState] == HockeyAuthorizationPending) { if ([self authorizationState] == HockeyAuthorizationPending) {
[self showAuthorizationScreen:BWHockeyLocalize(@"HockeyAuthorizationProgress") image:@"authorize_request.png"]; [self showAuthorizationScreen:BWHockeyLocalize(@"HockeyAuthorizationProgress") image:@"authorize_request.png"];
@ -988,73 +983,76 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
[self connectionClosed_]; [self connectionClosed_];
self.checkInProgress = NO; self.checkInProgress = NO;
if ([self.receivedData length]) { if ([self.receivedData length]) {
NSString *responseString = [[[NSString alloc] initWithBytes:[receivedData_ bytes] length:[receivedData_ length] encoding: NSUTF8StringEncoding] autorelease]; NSString *responseString = [[[NSString alloc] initWithBytes:[receivedData_ bytes] length:[receivedData_ length] encoding: NSUTF8StringEncoding] autorelease];
BWHockeyLog(@"Received API response: %@", responseString); BWHockeyLog(@"Received API response: %@", responseString);
id json = [self parseJSONResultString:responseString]; id json = [self parseJSONResultString:responseString];
NSArray *feedArray = (NSArray *)([self checkForTracker] ? [json valueForKey:@"versions"] : json);
self.trackerConfig = ([self checkForTracker] ? [json valueForKey:@"tracker"] : nil); self.trackerConfig = ([self checkForTracker] ? [json valueForKey:@"tracker"] : nil);
self.receivedData = nil;
self.urlConnection = nil;
// remember that we just checked the server if (![self isAppStoreEnvironment]) {
self.lastCheck = [NSDate date]; NSArray *feedArray = (NSArray *)([self checkForTracker] ? [json valueForKey:@"versions"] : json);
// server returned empty response? self.receivedData = nil;
if (![feedArray count]) { self.urlConnection = nil;
[self reportError_:[NSError errorWithDomain:kHockeyErrorDomain code:HockeyAPIServerReturnedEmptyResponse userInfo:
[NSDictionary dictionaryWithObjectsAndKeys:@"Server returned empty response.", NSLocalizedDescriptionKey, nil]]]; // remember that we just checked the server
return; self.lastCheck = [NSDate date];
} else {
lastCheckFailed_ = NO; // server returned empty response?
} if (![feedArray count]) {
[self reportError_:[NSError errorWithDomain:kHockeyErrorDomain code:HockeyAPIServerReturnedEmptyResponse userInfo:
[NSDictionary dictionaryWithObjectsAndKeys:@"Server returned empty response.", NSLocalizedDescriptionKey, nil]]];
NSString *currentAppCacheVersion = [[[self app].version copy] autorelease]; return;
// clear cache and reload with new data
NSMutableArray *tmpApps = [NSMutableArray arrayWithCapacity:[feedArray count]];
for (NSDictionary *dict in feedArray) {
BWApp *app = [BWApp appFromDict:dict];
if ([app isValid]) {
[tmpApps addObject:app];
} else { } else {
[self reportError_:[NSError errorWithDomain:kHockeyErrorDomain code:HockeyAPIServerReturnedInvalidData userInfo: lastCheckFailed_ = NO;
[NSDictionary dictionaryWithObjectsAndKeys:@"Invalid data received from server.", NSLocalizedDescriptionKey, nil]]];
} }
}
// only set if different!
if (![self.apps isEqualToArray:tmpApps]) { NSString *currentAppCacheVersion = [[[self app].version copy] autorelease];
self.apps = [[tmpApps copy] autorelease];
} // clear cache and reload with new data
[self saveAppCache_]; NSMutableArray *tmpApps = [NSMutableArray arrayWithCapacity:[feedArray count]];
for (NSDictionary *dict in feedArray) {
[self checkUpdateAvailable_]; BWApp *app = [BWApp appFromDict:dict];
BOOL newVersionDiffersFromCachedVersion = ![self.app.version isEqualToString:currentAppCacheVersion]; if ([app isValid]) {
[tmpApps addObject:app];
// show alert if we are on the latest & greatest } else {
if (showFeedback_ && !self.isUpdateAvailable) { [self reportError_:[NSError errorWithDomain:kHockeyErrorDomain code:HockeyAPIServerReturnedInvalidData userInfo:
// use currentVersionString, as version still may differ (e.g. server: 1.2, client: 1.3) [NSDictionary dictionaryWithObjectsAndKeys:@"Invalid data received from server.", NSLocalizedDescriptionKey, nil]]];
NSString *versionString = [self currentAppVersion]; }
NSString *shortVersionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
shortVersionString = shortVersionString ? [NSString stringWithFormat:@"%@ ", shortVersionString] : @"";
versionString = [shortVersionString length] ? [NSString stringWithFormat:@"(%@)", versionString] : versionString;
NSString *currentVersionString = [NSString stringWithFormat:@"%@ %@ %@%@", self.app.name, BWHockeyLocalize(@"HockeyVersion"), shortVersionString, versionString];
NSString *alertMsg = [NSString stringWithFormat:BWHockeyLocalize(@"HockeyNoUpdateNeededMessage"), currentVersionString];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:BWHockeyLocalize(@"HockeyNoUpdateNeededTitle") message:alertMsg delegate:nil cancelButtonTitle:BWHockeyLocalize(@"HockeyOK") otherButtonTitles:nil];
[alert show];
[alert release];
}
if (self.isUpdateAvailable && (self.alwaysShowUpdateReminder || newVersionDiffersFromCachedVersion || [self.app.mandatory boolValue])) {
if (updateAvailable_ && !currentHockeyViewController_) {
[self showCheckForUpdateAlert_];
} }
// only set if different!
if (![self.apps isEqualToArray:tmpApps]) {
self.apps = [[tmpApps copy] autorelease];
}
[self saveAppCache_];
[self checkUpdateAvailable_];
BOOL newVersionDiffersFromCachedVersion = ![self.app.version isEqualToString:currentAppCacheVersion];
// show alert if we are on the latest & greatest
if (showFeedback_ && !self.isUpdateAvailable) {
// use currentVersionString, as version still may differ (e.g. server: 1.2, client: 1.3)
NSString *versionString = [self currentAppVersion];
NSString *shortVersionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
shortVersionString = shortVersionString ? [NSString stringWithFormat:@"%@ ", shortVersionString] : @"";
versionString = [shortVersionString length] ? [NSString stringWithFormat:@"(%@)", versionString] : versionString;
NSString *currentVersionString = [NSString stringWithFormat:@"%@ %@ %@%@", self.app.name, BWHockeyLocalize(@"HockeyVersion"), shortVersionString, versionString];
NSString *alertMsg = [NSString stringWithFormat:BWHockeyLocalize(@"HockeyNoUpdateNeededMessage"), currentVersionString];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:BWHockeyLocalize(@"HockeyNoUpdateNeededTitle") message:alertMsg delegate:nil cancelButtonTitle:BWHockeyLocalize(@"HockeyOK") otherButtonTitles:nil];
[alert show];
[alert release];
}
if (self.isUpdateAvailable && (self.alwaysShowUpdateReminder || newVersionDiffersFromCachedVersion || [self.app.mandatory boolValue])) {
if (updateAvailable_ && !currentHockeyViewController_) {
[self showCheckForUpdateAlert_];
}
}
showFeedback_ = NO;
} }
showFeedback_ = NO; } else {
}else {
[self reportError_:[NSError errorWithDomain:kHockeyErrorDomain code:HockeyAPIServerReturnedEmptyResponse userInfo: [self reportError_:[NSError errorWithDomain:kHockeyErrorDomain code:HockeyAPIServerReturnedEmptyResponse userInfo:
[NSDictionary dictionaryWithObjectsAndKeys:@"Server returned an empty response.", NSLocalizedDescriptionKey, nil]]]; [NSDictionary dictionaryWithObjectsAndKeys:@"Server returned an empty response.", NSLocalizedDescriptionKey, nil]]];
} }
@ -1080,16 +1078,14 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
} }
BW_IF_IOS4_OR_GREATER( BW_IF_IOS4_OR_GREATER(
if (!isAppStoreEnvironment_) { // register/deregister logic
// register/deregister logic NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter]; if (!updateURL_ && anUpdateURL) {
if (!updateURL_ && anUpdateURL) { [dnc addObserver:self selector:@selector(startUsage) name:UIApplicationDidBecomeActiveNotification object:nil];
[dnc addObserver:self selector:@selector(startUsage) name:UIApplicationDidBecomeActiveNotification object:nil]; [dnc addObserver:self selector:@selector(stopUsage) name:UIApplicationWillResignActiveNotification object:nil];
[dnc addObserver:self selector:@selector(stopUsage) name:UIApplicationWillResignActiveNotification object:nil]; } else if (updateURL_ && !anUpdateURL) {
} else if (updateURL_ && !anUpdateURL) { [dnc removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
[dnc removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil]; [dnc removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[dnc removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
}
} }
) )
@ -1098,9 +1094,7 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
updateURL_ = [anUpdateURL copy]; updateURL_ = [anUpdateURL copy];
} }
if (!isAppStoreEnvironment_) { [self performSelector:@selector(startManager) withObject:nil afterDelay:0.0f];
[self performSelector:@selector(startManager) withObject:nil afterDelay:0.0f];
}
} }
- (void)setAppIdentifier:(NSString *)anAppIdentifier { - (void)setAppIdentifier:(NSString *)anAppIdentifier {
@ -1116,13 +1110,11 @@ static NSString *kHockeyErrorDomain = @"HockeyErrorDomain";
if (checkForUpdateOnLaunch_ != flag) { if (checkForUpdateOnLaunch_ != flag) {
checkForUpdateOnLaunch_ = flag; checkForUpdateOnLaunch_ = flag;
BW_IF_IOS4_OR_GREATER( BW_IF_IOS4_OR_GREATER(
if (!isAppStoreEnvironment_) { NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter]; if (flag) {
if (flag) { [dnc addObserver:self selector:@selector(checkForUpdate) name:UIApplicationDidBecomeActiveNotification object:nil];
[dnc addObserver:self selector:@selector(checkForUpdate) name:UIApplicationDidBecomeActiveNotification object:nil]; } else {
} else { [dnc removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
[dnc removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
}
} }
) )
} }

View File

@ -136,12 +136,12 @@
if ([self shouldUseLiveIdenfitier]) { if ([self shouldUseLiveIdenfitier]) {
appIdentifier = [liveIdentifier copy]; appIdentifier = [liveIdentifier copy];
[self configureQuincyManager];
} }
else { else {
appIdentifier = [betaIdentifier copy]; appIdentifier = [betaIdentifier copy];
}
if (appIdentifier) {
[self configureQuincyManager]; [self configureQuincyManager];
[self configureHockeyManager]; [self configureHockeyManager];
} }