123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- //
- // MainViewController.m
- // OpenLive
- //
- // Created by GongYuhua on 2016/9/12.
- // Copyright © 2016年 Agora. All rights reserved.
- //
- #import "MainViewController.h"
- #import "SettingsViewController.h"
- #import "LiveRoomViewController.h"
- #import "MyInterfaceController.h"
- #import "OLglobal.h"
- #import <PgyUpdate/PgyUpdateManager.h>
- //设置倒计时相关
- #define PGY_APP_ID @"c9f036f976eb6ccd2e0350418c31bc98"
- #define Func NSLog(@"func :%s",__FUNCTION__);
- @interface MainViewController () <SettingsVCDelegate, LiveRoomVCDelegate, UITextFieldDelegate>
- //断开重连
- @property (weak, nonatomic) IBOutlet UISwitch *reconnectionSwitch;
- //@property (weak, nonatomic) IBOutlet UILabel *status;
- //隔天重连
- @property (weak, nonatomic) IBOutlet UILabel *versionCode;
- @property (weak, nonatomic) IBOutlet UISwitch *reconnectionNextDaySwitch;
- @property (weak, nonatomic) IBOutlet UILabel *build;
- @property (weak, nonatomic) IBOutlet UITextField *uidTextField;
- @property (weak, nonatomic) IBOutlet UITextField *roomNameTextField;
- @property (weak, nonatomic) IBOutlet UIView *popoverSourceView;
- @property (assign, nonatomic) AgoraRtcVideoProfile videoProfile;
- @property(nonatomic,strong) MyInterfaceController *inter;
- //倒计时进入相关
- @property (assign, nonatomic) int secondsCountDown; //倒计时总时长
- @property (strong, nonatomic) NSTimer *countDownTimer;
- @property (nonatomic,copy) NSString *secondsCountDownString;
- @property (strong, nonatomic) UIAlertController *alertCon;
- @property (assign, nonatomic) BOOL GoNext;
- @end
- @implementation MainViewController
- -(void)getVersionCode{
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
- NSString *version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
- self.versionCode.text=[NSString stringWithFormat:@"当前版本号:%@",version];
- self.versionCode.font=[UIFont systemFontOfSize:14.0f];
- self.versionCode.textColor=[UIColor redColor];
- }
- -(void)buildCode{
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
- NSString *build = [infoDictionary objectForKey:@"CFBundleVersion"];
- self.build.text=[NSString stringWithFormat:@"当前build号:%@",build];
- self.build.font=[UIFont systemFontOfSize:14.0f];
- self.build.textColor=[UIColor greenColor];
- }
- -(MyInterfaceController *)inter{
- if (!_inter) {
- _inter=[[MyInterfaceController alloc]init];
- }
- return _inter;
- }
- #pragma mark 加载视图
- //xib加载完后
- -(void)awakeFromNib{
- [super awakeFromNib];
-
-
-
-
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setConfiguration];
- self.videoProfile = AgoraRtc_VideoProfile_480P;
- [self inter];
- [self userAdd];
- [self buildCode];
- [self getVersionCode];
- //启动基本SDK
- // [[PgyManager sharedPgyManager] startManagerWithAppId:PGY_APP_ID];
- // [[PgyUpdateManager sharedPgyManager] startManagerWithAppId:PGY_APP_ID];
- }
- -(void)userAdd{
- NSString *rootName;
- NSString *UID;
-
- rootName=[[NSUserDefaults standardUserDefaults] objectForKey:@"RootName"];
- UID=[[NSUserDefaults standardUserDefaults] objectForKey:@"UID"];
-
- if (nil!=rootName) {
- self.roomNameTextField.text=rootName;
- }
- if (nil!=UID) {
- self.uidTextField.text=UID;
- }
-
-
- }
- #pragma mark 基本设置
- -(void)setConfiguration{
- self.uidTextField.keyboardType=UIKeyboardTypeNumberPad;
- self.uidTextField.returnKeyType=UIReturnKeyNext;
- self.roomNameTextField.returnKeyType=UIReturnKeyNext;
-
- }
- #pragma mark 下一页按钮
- - (IBAction)nextPageGo:(id)sender {
- //消失弹窗
- if (![self.alertCon isKindOfClass:[NSNull class]]) {
- [self.alertCon dismissViewControllerAnimated:YES completion:^{
- NSLog(@"消失弹窗");
- }];
- }
-
- //首先判断text是否有数据
- if ([self.roomNameTextField.text isEqualToString:@""] || [self.uidTextField.text isEqualToString:@""]) {
- [self showAlertCon];
- return;
- }else{
- [[NSUserDefaults standardUserDefaults] setObject:self.roomNameTextField.text forKey:@"RootName"];
- [[NSUserDefaults standardUserDefaults] setObject:self.uidTextField.text forKey:@"UID"];
- [[NSUserDefaults standardUserDefaults]synchronize];
- //判断是否是自动进入,判断switch
- if (sender==nil) {
- //自动进入
- if(self.GoNext==YES){
- [self joinWithRole:AgoraRtc_ClientRole_Broadcaster];
- }
- }else{
- [self joinWithRole:AgoraRtc_ClientRole_Broadcaster];
- }
- }
- }
- - (void)showAlertCon{
- UIAlertController *sheet = [UIAlertController alertControllerWithTitle:@"提示" message:@"有内容没有输入" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *broadcaster = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- }];
-
- [sheet addAction:broadcaster];
- [self presentViewController:sheet animated:YES completion:nil];
- NSLog(@"不用了");
- }
- #pragma mark storyborad页面跳转时调用
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- NSString *segueId = segue.identifier;
- if ([segueId isEqualToString:@"mainToSettings"]) {
- SettingsViewController *settingsVC = segue.destinationViewController;
- settingsVC.videoProfile = self.videoProfile;
- settingsVC.delegate = self;
- } else if ([segueId isEqualToString:@"mainToLive"]) {
- LiveRoomViewController *liveVC = segue.destinationViewController;
- liveVC.roomName = self.roomNameTextField.text;
- liveVC.reconnectionNextDay=self.reconnectionNextDaySwitch.on;
- //未解决 有符号转换无符号long
- liveVC.uid = [self.uidTextField.text longLongValue];
- liveVC.videoProfile = self.videoProfile;
- liveVC.clientRole = [sender integerValue];
- liveVC.delegate = self;
-
- }
- }
- #pragma mark 模态跳转页面
- - (void)joinWithRole:(AgoraRtcClientRole)role {
- [self performSegueWithIdentifier:@"mainToLive" sender:@(role)];
- }
- #pragma mark -取消第一响应
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- {
- [self.roomNameTextField resignFirstResponder];
- [self.uidTextField resignFirstResponder];
-
- }
- #pragma mark SettingsVCDelegate
- - (void)settingsVC:(SettingsViewController *)settingsVC didSelectProfile:(AgoraRtcVideoProfile)profile {
- self.videoProfile = profile;
- //返回页面
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma mark LiveRoomVCDelegate
- - (void)liveVCNeedClose:(LiveRoomViewController *)liveVC {
- [self.navigationController popViewControllerAnimated:YES];
- //弹框显示,默认一分钟后重新进入界面
- if(self.reconnectionSwitch.on==YES){
- NSLog(@"正在重新连接");
- //弹窗出现倒计时 1分钟
- [self reconnectionTimer];
- }
- }
- //倒计时重连
- -(void)reconnectionTimer{
- Func
- self.GoNext=YES;
- _secondsCountDown = 3;//60秒倒计时
- _secondsCountDownString=[NSString stringWithFormat:@"\n%@",@(self.secondsCountDown)];
- //弹窗
- _alertCon=[UIAlertController alertControllerWithTitle:@"倒计时" message:self.secondsCountDownString preferredStyle:UIAlertControllerStyleAlert];
- NSLog(@"curr %@",NSThread.currentThread);
- UIAlertAction *alertAct1=[UIAlertAction actionWithTitle:@"停止进入" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- self.GoNext=NO;
- NSLog(@"点击了停止进入");
- [self.countDownTimer invalidate];
- }];
- [self.alertCon addAction:alertAct1];
- [self presentViewController:self.alertCon animated:YES completion:^{
- NSLog(@"弹窗");
- }];
- //开启倒计时模式
- _countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
- }
- //倒计时循环调用函数
- -(void)timeFireMethod{
- //倒计时-1
- NSLog(@"倒计时进入");
- self.secondsCountDown--;
- //修改倒计时标签现实内容
- NSLog(@"%i ",self.secondsCountDown);
- self.secondsCountDownString=[NSString stringWithFormat:@"\n%i",self.secondsCountDown];
- self.alertCon.message=self.secondsCountDownString;
- NSLog(@"3:%@",self.secondsCountDownString);
- //当倒计时到0时,做需要的操作,比如验证码过期不能提交
- if(self.secondsCountDown==0){
- [self.countDownTimer invalidate];
- self.countDownTimer=nil;
-
- self.secondsCountDownString=[NSString stringWithFormat:@"\n正在进入..."];
- self.alertCon.message=self.secondsCountDownString;
- //调用进入函数
- if (self.reconnectionSwitch.on==YES) {
- [self performSelector:@selector(nextPageGo:) withObject:nil afterDelay:1.0f];
- }
- }
- }
- #pragma mark -textFielddelegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return YES;
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
- if (textField==self.uidTextField) {//uid只允许输入数字,只能是整数
- if (range.length==1) {
- return YES;
- }
- if ([@"0123456789" rangeOfString:string].location == NSNotFound) {
- return NO;
- }
- if([textField.text length]>10){
- return NO;
- }
- }
- return YES;
- }
- - (IBAction)updateZWW:(id)sender {
- [[PgyUpdateManager sharedPgyManager] startManagerWithAppId:@"c9f036f976eb6ccd2e0350418c31bc98"]; // 请将 PGY_APP_ID 换成应用的 App Key
- [[PgyUpdateManager sharedPgyManager] checkUpdate];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- NSLog(@"main内存不够了");
- }
- @end
|