Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // MyViewController.m
- // Attention:
- // MyViewController.h <UIAlertViewDelegate>
- #import "MyViewController.h"
- #import "MyAppDelegate.h"
- #import "MySync.h"
- @interface MyViewController ()
- @end
- @implementation MyViewController {
- UIAlertView *alertViewFirstSync;
- UIAlertView *alertViewWait;
- UIAlertView *alertViewDownload;
- UIProgressView *progressView;
- }
- - (void)viewDidLoad
- {
- [self checkSync];
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (IBAction)gotoCategories:(id)sender
- {
- [MyAppDelegate openStoryboardByName:self name:@"CategoriesStoryboard"];
- }
- - (void)checkSync
- {
- BOOL firstSyncComplete = [[NSUserDefaults standardUserDefaults] boolForKey:@"firstSyncComplete"];
- if (firstSyncComplete == TRUE) {
- //pending...
- } else {
- [self firstSync];
- }
- }
- - (void)firstSync
- {
- alertViewFirstSync = [[UIAlertView alloc] initWithTitle:@"Atención" message:@"The App need sync" delegate:self cancelButtonTitle:FALSE otherButtonTitles:@"OK", nil];
- [alertViewFirstSync show];
- }
- - (void)alertView:(UIAlertView *)alertViewFirstSync clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (buttonIndex == 0) {
- [alertViewFirstSync dismissWithClickedButtonIndex:buttonIndex animated:TRUE];
- [self sync];
- }
- }
- - (void)sync
- {
- alertViewWait = [[UIAlertView alloc] initWithTitle:@"Information" message:@"Connecting... please wait..." delegate:nil cancelButtonTitle:FALSE otherButtonTitles:FALSE, nil];
- UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(130.0, 85.0, 20.0, 20.0)];
- [activityIndicatorView startAnimating];
- [alertViewWait addSubview:activityIndicatorView];
- [alertViewWait show];
- [self startSync];
- }
- - (void)startSync
- {
- progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
- [progressView setFrame:CGRectMake(30, 100, 225, 20)];
- [[MySync alloc] start:self progressView:progressView];
- }
- - (void)syncJSonComplete
- {
- [self performSelector:@selector(dismissAlertView:) withObject:alertViewWait afterDelay:0.2];
- [self performSelector:@selector(showAlertViewDownload) withObject:nil afterDelay:0.3];
- }
- - (void)showAlertViewDownload
- {
- alertViewDownload = [[UIAlertView alloc] initWithTitle:@"Downloading" message:@"Please wait..." delegate:nil cancelButtonTitle:FALSE otherButtonTitles:FALSE, nil];
- [alertViewDownload addSubview:progressView];
- [alertViewDownload show];
- }
- - (void)syncComplete
- {
- NSLog(@"SynComplete on ViewController");
- [self performSelector:@selector(dismissAlertView:) withObject:alertViewDownload afterDelay:0.5];
- }
- - (void)setProgressView:(float)progress
- {
- [progressView setProgress:progress];
- }
- - (void)dismissAlertView:(UIAlertView *)alertView
- {
- NSLog(@"dismiss alertview");
- [alertView dismissWithClickedButtonIndex:0 animated:TRUE];
- alertView = nil;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement