Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "TGUpdateAppController.h"
  2.  
  3. #import "TGApplication.h"
  4.  
  5. #import "TGUpdateAppInfo.h"
  6. #import "TGUpdateAppInfoItem.h"
  7. #import "TGButtonCollectionItem.h"
  8.  
  9. @interface TGUpdateAppController ()
  10. {
  11.     TGUpdateAppInfo *_updateInfo;
  12. }
  13. @end
  14.  
  15. @implementation TGUpdateAppController
  16.  
  17. - (instancetype)initWithUpdateInfo:(TGUpdateAppInfo *)updateInfo
  18. {
  19.     self = [super init];
  20.     if (self != nil)
  21.     {
  22.         _updateInfo  = updateInfo;
  23.        
  24.         self.title = TGLocalized(@"Update.Title");
  25.        
  26.         if (updateInfo.popup)
  27.         {
  28.             self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:TGLocalized(@"Update.Skip") style:UIBarButtonItemStylePlain target:self action:@selector(cancelPressed)];
  29.         }
  30.        
  31.         TGUpdateAppInfoItem *infoItem = [[TGUpdateAppInfoItem alloc] init];
  32.         infoItem.title = [NSString stringWithFormat:TGLocalized(@"Update.AppVersion"), updateInfo.version];
  33.         infoItem.text = updateInfo.text;
  34.         infoItem.entities = updateInfo.entities;
  35.         infoItem.followLink = ^(NSString *url)
  36.         {
  37.             [(TGApplication *)[TGApplication sharedApplication] nativeOpenURL:[NSURL URLWithString:url]];
  38.         };
  39.        
  40.         TGCollectionMenuSection *infoSection = [[TGCollectionMenuSection alloc] initWithItems:@[infoItem]];
  41.         [self.menuSections addSection:infoSection];
  42.        
  43.         TGButtonCollectionItem *updateItem = [[TGButtonCollectionItem alloc] initWithTitle:TGLocalized(@"Update.UpdateApp") action:@selector(updatePressed)];
  44.         updateItem.alignment = NSTextAlignmentCenter;
  45.         updateItem.deselectAutomatically = true;
  46.         TGCollectionMenuSection *buttonSection = [[TGCollectionMenuSection alloc] initWithItems:@[updateItem]];
  47.         [self.menuSections addSection:buttonSection];
  48.        
  49.         if (self.menuSections.sections.count != 0) {
  50.             UIEdgeInsets topSectionInsets = ((TGCollectionMenuSection *)self.menuSections.sections[0]).insets;
  51.             topSectionInsets.top = 32.0f;
  52.             ((TGCollectionMenuSection *)self.menuSections.sections[0]).insets = topSectionInsets;
  53.         }
  54.     }
  55.     return self;
  56. }
  57.  
  58. - (void)cancelPressed
  59. {
  60.     [self.presentingViewController dismissViewControllerAnimated:true completion:nil];
  61. }
  62.  
  63. - (void)updatePressed
  64. {
  65.     NSNumber *appStoreId = @686449807;
  66. #ifdef TELEGRAM_APPSTORE_ID
  67.     appStoreId = TELEGRAM_APPSTORE_ID;
  68. #endif
  69.     NSURL *appStoreURL = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@", appStoreId]];
  70.     [[UIApplication sharedApplication] openURL:appStoreURL];
  71. }
  72.  
  73. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement