//
//  ViewController.m
//  GInsightSDKUserDemo
//
//  Created by j on 16/9/1.
//  Copyright © 2016年 hj. All rights reserved.
//

#define GIUID_KEY @"giuid_key"

#import "ViewController.h"
#import "GInsightSDK.h"
#import <CoreLocation/CoreLocation.h>

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *giVersionLabel;

@property (weak, nonatomic) IBOutlet UILabel *giUidLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.giVersionLabel.text = [GInsightSDK version];
    NSString *giuid = [[NSUserDefaults standardUserDefaults] objectForKey:GIUID_KEY];
    if (giuid) {
        _giUid= giuid;
        self.giUidLabel.text = giuid;
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setGiUid:(NSString *)giUid{
    _giUid = [giUid copy];
    dispatch_async(dispatch_get_main_queue(), ^{
         self.giUidLabel.text = _giUid;
        [[NSUserDefaults standardUserDefaults] setObject:_giUid forKey:GIUID_KEY];
    });
}

- (IBAction)searchTagClick:(id)sender{
    if (!self.giUid) {
        return;
    }
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://demo-gi.getui.com/?os=ios&giuid=%@",self.giUid]];
    
    [[UIApplication sharedApplication] openURL:url];

}

- (IBAction)pastedClick:(id)sender{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.giUidLabel.text;
}

@end
