Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,21 @@
//
// NTESFilePreViewController.h
// NIM
//
// Created by chris on 15/4/21.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface NTESFilePreViewController : UIViewController
@property(nonatomic,strong) IBOutlet UIButton *actionBtn;
@property(nonatomic,strong) IBOutlet UIProgressView *progressView;
@property(nonatomic,strong) IBOutlet UILabel *fileNameLabel;
- (instancetype)initWithFileObject:(NIMFileObject*)object;
@end
@@ -0,0 +1,102 @@
//
// NTESFilePreViewController.m
// NIM
//
// Created by chris on 15/4/21.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import "NTESFilePreViewController.h"
#import <MobileCoreServices/MobileCoreServices.h>
@interface NTESFilePreViewController ()
@property(nonatomic,strong)NIMFileObject *fileObject;
@property(nonatomic,strong)UIDocumentInteractionController *interactionController;
@property(nonatomic,assign)BOOL isDownLoading;
@end
@implementation NTESFilePreViewController
- (instancetype)initWithFileObject:(NIMFileObject*)object{
self = [super initWithNibName:nil bundle:nil];
if (self) {
_fileObject = object;
}
return self;
}
- (void)dealloc{
[[NIMSDK sharedSDK].resourceManager cancelTask:_fileObject.path];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = self.fileObject.displayName;
self.fileNameLabel.text = self.fileObject.displayName;
NSString *filePath = self.fileObject.path;
self.progressView.hidden = YES;
[self.actionBtn addTarget:self action:@selector(touchUpBtn) forControlEvents:UIControlEventTouchUpInside];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
[self.actionBtn setTitle:@"用其他应用程序打开" forState:UIControlStateNormal];
}else{
[self.actionBtn setTitle:@"下载文件" forState:UIControlStateNormal];
}
}
- (void)touchUpBtn{
NSString *filePath = self.fileObject.path;
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
[self openWithOtherApp];
}else{
if (self.isDownLoading) {
[[NIMSDK sharedSDK].resourceManager cancelTask:filePath];
self.progressView.hidden = YES;
self.progressView.progress = 0.0;
[self.actionBtn setTitle:@"下载文件" forState:UIControlStateNormal];
self.isDownLoading = NO;
}else{
[self downLoadFile];
}
}
}
#pragma mark - 文件下载
- (void)downLoadFile{
NSString *url = self.fileObject.url;
__weak typeof(self) wself = self;
[[NIMSDK sharedSDK].resourceManager download:url filepath:self.fileObject.path progress:^(float progress) {
wself.isDownLoading = YES;
wself.progressView.hidden = NO;
wself.progressView.progress = progress;
[wself.actionBtn setTitle:@"取消下载" forState:UIControlStateNormal];
} completion:^(NSError *error) {
wself.isDownLoading = NO;
wself.progressView.hidden = YES;
if (!error) {
[wself.actionBtn setTitle:@"用其他应用程序打开" forState:UIControlStateNormal];
}else{
wself.progressView.progress = 0.0f;
[wself.actionBtn setTitle:@"下载失败,点击重新下载" forState:UIControlStateNormal];
}
}];
}
#pragma mark - 其他应用打开
- (void)openWithOtherApp{
self.interactionController =
[UIDocumentInteractionController
interactionControllerWithURL:[NSURL fileURLWithPath:self.fileObject.path]];
if (![self.interactionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"未找到打开该应用的程序" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
[alert show];
}
}
@end
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="NTESFilePreViewController">
<connections>
<outlet property="actionBtn" destination="LnM-xY-yMN" id="f9e-hN-uwu"/>
<outlet property="fileNameLabel" destination="lmE-BL-6d7" id="XWn-uR-jGp"/>
<outlet property="progressView" destination="RFS-rb-FsG" id="b9b-2x-XUE"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon_file.png" id="pIa-MW-aQh">
<rect key="frame" x="128" y="133" width="65" height="80"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="LnM-xY-yMN">
<rect key="frame" x="59" y="330" width="203" height="46"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<state key="normal" title="Button" backgroundImage="btn_launch_button_normal_0.png">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
</button>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" id="RFS-rb-FsG">
<rect key="frame" x="85" y="297" width="150" height="2"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</progressView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="lmE-BL-6d7">
<rect key="frame" x="23" y="227" width="275" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<point key="canvasLocation" x="310" y="229"/>
</view>
</objects>
<resources>
<image name="btn_launch_button_normal_0.png" width="148" height="46"/>
<image name="icon_file.png" width="65" height="80"/>
</resources>
</document>
@@ -0,0 +1,19 @@
//
// FileTransSelectViewController.h
// NIM
//
// Created by chris on 15/4/20.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef void(^NTESFileTransCompletionBlock)(id sender,NSString* ext);
@interface NTESFileTransSelectViewController : UIViewController
@property(nonatomic,strong) IBOutlet UITableView *tableView;
@property(nonatomic,copy)NTESFileTransCompletionBlock completionBlock;
@end
@@ -0,0 +1,67 @@
//
// FileTransSelectViewController.m
// NIM
//
// Created by chris on 15/4/20.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import "NTESFileTransSelectViewController.h"
#define FileName @"fileName"
#define FileExt @"fileExt"
@interface NTESFileTransSelectViewController ()
@property(nonatomic,strong) NSArray *data;
@end
@implementation NTESFileTransSelectViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"文件列表";
self.tableView.tableFooterView = [[UIView alloc] init];
self.data = [[NSBundle mainBundle] pathsForResourcesOfType:nil inDirectory:@"Files"];
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.navigationController popViewControllerAnimated:YES];
NSString *filePath = self.data[indexPath.row];
if (self.completionBlock) {
if (indexPath.row % 2 == 0) {
self.completionBlock(filePath,filePath.pathExtension);
self.completionBlock = nil;
}else{
NSData *data = [NSData dataWithContentsOfFile:filePath];
self.completionBlock(data,filePath.pathExtension);
self.completionBlock = nil;
}
}
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
NSString *path = self.data[indexPath.row];
if (indexPath.row % 2 == 0) {
cell.textLabel.text = path.lastPathComponent;
}else{
cell.textLabel.text = [path.lastPathComponent stringByAppendingString:@"(DATA 传输)"];
}
return cell;
}
@end
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="NTESFileTransSelectViewController">
<connections>
<outlet property="tableView" destination="mpd-wR-P0a" id="ATr-sb-V8S"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="mpd-wR-P0a">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<outlet property="dataSource" destination="-1" id="YZY-eL-eva"/>
<outlet property="delegate" destination="-1" id="F8N-I3-JHb"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<point key="canvasLocation" x="310" y="229"/>
</view>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>