Added main delegate methods for setting up 'test' and 'beta' updates checking.

This commit is contained in:
Dmytro Tretiakov committed 2015-07-06 18:10:21 +03:00
1 parent 90f35f87dc
commit dd3aca874b
2 files changed
+66 -1

No files matched your search

+29
View File
@@ -325,4 +325,33 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
@end
// -----------------------------------------------------------------------------
// SUUpdater Delegate: DevMate Interaction
// -----------------------------------------------------------------------------
// NOTE!!! Implemented delegate methods have higher priority than values saved in user preferences
static NSString * const SUUpdaterChecksForBetaUpdatesPrefKey = @"SUUpdaterChecksForBetaUpdates"; // bool value
static NSString * const SUUpdaterIsInTestModePrefKey = @"SUUpdaterIsInTestMode"; // bool value
@protocol SUUpdaterDelegate_DevMateInteraction <SUUpdaterDelegate>
@optional
/*!
Calls right before updates checking request to look for beta ones on DevMate.
\param updater The SUUpdater instance.
\return YES if need also check beta updates, NO otherwise.
*/
- (BOOL)updaterShouldCheckForBetaUpdates:(SUUpdater *)updater;
/*!
Calls right before updates checking request to look for updates in test mode on DevMate.
\param updater The SUUpdater instance.
\return YES if need to check updates that are in test mode, NO otherwise.
*/
- (BOOL)isUpdaterInTestMode:(SUUpdater *)updater;
@end
#endif
+37 -1
View File
@@ -448,7 +448,14 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
// A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds).
NSString *appcastString = [self.host objectForKey:SUFeedURLKey];
if ([self.delegate respondsToSelector:@selector(feedURLStringForUpdater:)])
{
appcastString = [self.delegate feedURLStringForUpdater:self];
}
if (0 == appcastString.length)
{
appcastString = @"https://updates.devmate.com/";
}
if (!appcastString) // Can't find an appcast string!
[NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the %@ key in either the Info.plist or the user defaults!", SUFeedURLKey];
NSCharacterSet *quoteSet = [NSCharacterSet characterSetWithCharactersInString:@"\"\'"]; // Some feed publishers add quotes; strip 'em.
@@ -496,7 +503,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
const NSTimeInterval oneWeek = 60 * 60 * 24 * 7;
sendingSystemProfile &= (-[lastSubmitDate timeIntervalSinceNow] >= oneWeek);
NSArray *parameters = @[];
NSArray *parameters = [self devmateFeedParameters];
if ([self.delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)]) {
parameters = [parameters arrayByAddingObjectsFromArray:[self.delegate feedParametersForUpdater:self sendingSystemProfile:sendingSystemProfile]];
}
@@ -566,4 +573,33 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
- (NSBundle *)hostBundle { return [self.host bundle]; }
#pragma mark - DevMate Interaction
- (NSArray *)devmateFeedParameters
{
NSMutableArray *parameters = [NSMutableArray array];
BOOL isInTestMode = [self.host boolForUserDefaultsKey:SUUpdaterIsInTestModePrefKey];
if ([self.delegate respondsToSelector:@selector(isUpdaterInTestMode:)])
{
isInTestMode = [(id<SUUpdaterDelegate_DevMateInteraction>)self.delegate isUpdaterInTestMode:self];
}
if (isInTestMode)
{
[parameters addObject:@{ @"key" : @"test", @"value" : @"1"}];
}
BOOL shouldCheckBeta = [self.host boolForUserDefaultsKey:SUUpdaterChecksForBetaUpdatesPrefKey];
if ([self.delegate respondsToSelector:@selector(updaterShouldCheckForBetaUpdates:)])
{
shouldCheckBeta = [(id<SUUpdaterDelegate_DevMateInteraction>)self.delegate updaterShouldCheckForBetaUpdates:self];
}
if (shouldCheckBeta)
{
[parameters addObject:@{ @"key" : @"beta", @"value" : @"1"}];
}
return parameters;
}
@end