Jelajahi Sumber

[App Distribution] Add isExpired to FIRAppDistributionRelease (#6282)

Jeremy Durham 5 tahun lalu
induk
melakukan
85b705069d

+ 9 - 0
FirebaseAppDistribution/Sources/FIRAppDistributionRelease.m

@@ -19,9 +19,13 @@
 @property(nonatomic, copy) NSString *buildVersion;
 @property(nonatomic, copy) NSString *releaseNotes;
 @property(nonatomic, strong) NSURL *downloadURL;
+@property(nonatomic) NSDate *expirationTime;
 @end
 
 @implementation FIRAppDistributionRelease
+
+static const NSTimeInterval kDownloadUrlTimeToLive = 59 * 60;  // 59 minutes
+
 - (instancetype)initWithDictionary:(NSDictionary *)dict {
   self = [super init];
   if (self) {
@@ -30,7 +34,12 @@
 
     self.downloadURL = [[NSURL alloc] initWithString:[dict objectForKey:@"downloadUrl"]];
     self.releaseNotes = [dict objectForKey:@"releaseNotes"];
+    self.expirationTime = [NSDate dateWithTimeIntervalSinceNow:kDownloadUrlTimeToLive];
   }
   return self;
 }
+
+- (BOOL)isExpired {
+  return [[NSDate date] compare:_expirationTime] == NSOrderedDescending;
+}
 @end

+ 3 - 0
FirebaseAppDistribution/Sources/Public/FIRAppDistributionRelease.h

@@ -35,6 +35,9 @@ NS_SWIFT_NAME(AppDistributionRelease)
 // The URL for the build
 @property(nonatomic, strong, readonly) NSURL *downloadURL;
 
+// Whether the download URL for this release is expired
+@property(nonatomic, readonly) BOOL isExpired;
+
 /** :nodoc: */
 - (instancetype)init NS_UNAVAILABLE;