美文网首页
后台更改启动页

后台更改启动页

作者: _Jock羁 | 来源:发表于2016-08-08 10:58 被阅读68次
//生成图片的保存地址
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *path = [paths objectAtIndex:0];
            NSString *imagePath = [path stringByAppendingString:@"/launch.png"];
            //保存网络图片地址到偏好设置
            NSString *ImageUrl = [self.homes[0] objectForKey:@"ImageUrl"];
            NSString  *url = [[NSUserDefaults standardUserDefaults] valueForKey:@"ImageUrl"];
            //比较最新的网络地址和偏好设置的网络地址是否相同 相同则直接取值 不同则下载图片缓存;
            if ([ImageUrl isEqualToString: url]) {
    
                imageView.image =[UIImage imageWithContentsOfFile:imagePath];
                if (imageView.image == nil) {
                    NSLog(@"nil");
                    imageView.image = [UIImage imageNamed:@"launch"];
                }
               
            }else
            {
                

                //缓存图片
                imageView.image = [UIImage imageNamed:@"launch"];
                SDWebImageManager* mgr = [SDWebImageManager sharedManager];
                [mgr downloadImageWithURL:[NSURL URLWithString:ImageUrl] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                    
                } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                    
                    [UIImagePNGRepresentation(image) writeToFile:imagePath atomically:YES];
                }];
                
                //记录地址
                [[NSUserDefaults standardUserDefaults] setObject:ImageUrl forKey:@"ImageUrl"];
            }
            
            //两秒过后跳入主控制器
            [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(rootVC) userInfo:nil repeats:YES];

相关文章

网友评论

      本文标题:后台更改启动页

      本文链接:https://www.haomeiwen.com/subject/fsqrsttx.html