ThingsViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. //
  2. // ThingsViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 3/10/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "DeviceModel.h"
  12. #import "UIImageView+WebCache.h"
  13. #import "CustomLabel.h"
  14. #import "CustomImageView.h"
  15. #import "CustomTextField.h"
  16. #import "CustomButton.h"
  17. #import "JYRefreshController.h"
  18. #import "WYPopoverController.h"
  19. #import "ImageUtil.h"
  20. #import "CommandClassControlView.h"
  21. #import "ThingsDetailViewController.h"
  22. #import "ThingsViewController.h"
  23. #import "UIButton+WebCache.h"
  24. #import "ThingsAddViewController.h"
  25. #import "ThingsAddStartViewController.h"
  26. #define kfThingsTableViewCellHeight 100.0f
  27. @interface ThingsCollectionViewCell () {
  28. NSInteger _commandStatusElapsedTime;
  29. }
  30. @property (weak, nonatomic) NSIndexPath *indexPath;
  31. @end
  32. @implementation ThingsCollectionViewCell
  33. - (void)awakeFromNib {
  34. _btnDelete.hidden = YES;
  35. }
  36. @end
  37. @implementation ThingsAddCollectionViewCell
  38. @end
  39. @implementation ThingsCollectionFooterView
  40. @end
  41. @interface ThingsViewController () <UICollectionViewDataSource, UICollectionViewDelegate> {
  42. NSMutableArray<DeviceModel> *_deviceList;
  43. NSString *_pagingId, *_pagingType;
  44. BOOL _isNotFirstLoading, _isDeleteMode;
  45. NSMutableArray<DeviceModel> *_commandArray;
  46. NSTimer *_deviceCommandsBackgroundTimer;
  47. }
  48. @property (strong, nonatomic) JYPullToRefreshController *refreshController;
  49. @property (strong, nonatomic) JYPullToLoadMoreController *loadMoreController;
  50. @end
  51. #pragma mark - Class Definition
  52. @implementation ThingsViewController
  53. - (void)viewDidLoad {
  54. [super viewDidLoad];
  55. [self initUI];
  56. }
  57. - (void)viewWillAppear:(BOOL)animated {
  58. [super viewWillAppear:animated];
  59. [self prepareViewDidLoad];
  60. }
  61. - (void)initUI {
  62. //set tableview option
  63. _collectionView.delegate = self;
  64. _collectionView.dataSource = self;
  65. _collectionView.backgroundColor = kUIBgColor01;
  66. if ([JDFacade facade].loginUser.homehubDeviceId && ![[JDFacade facade].loginUser.homehubDeviceId isEmptyString]) {
  67. [self setThingsPopoverOptions];
  68. }
  69. //set refresh controls
  70. // __weak typeof(self) weakSelf = self;
  71. // self.refreshController = [[JYPullToRefreshController alloc] initWithScrollView:self.tableView];
  72. // self.refreshController.pullToRefreshHandleAction = ^{
  73. // [weakSelf requestPredefinedRulesRecently];
  74. // };
  75. //
  76. // self.loadMoreController = [[JYPullToLoadMoreController alloc] initWithScrollView:self.tableView];
  77. // self.loadMoreController.pullToLoadMoreHandleAction = ^{
  78. // [weakSelf requestPredefinedRulesOlder];
  79. // };
  80. }
  81. - (void)setThingsPopoverOptions {
  82. //set Popover Contents
  83. __weak typeof(self) weakSelf = self;
  84. _popooverOptionArray = [[NSMutableArray alloc] init];
  85. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로 고침",nil),
  86. @"iconName": @"tp_01_img_bg_morepopup_icon_refresh",
  87. @"target": weakSelf,
  88. @"selector": [NSValue valueWithPointer:@selector(refreshDeviceList)]}];
  89. if ([JDFacade facade].loginUser.level == 90) {//권한
  90. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"추가", @"추가"),
  91. @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
  92. @"target": weakSelf,
  93. @"selector": [NSValue valueWithPointer:@selector(addNewDevice)]}];
  94. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"삭제", @"삭제"),
  95. @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
  96. @"target": weakSelf,
  97. @"selector": [NSValue valueWithPointer:@selector(toggleEditMode)]}];
  98. }
  99. }
  100. - (void)prepareViewDidLoad {
  101. //fetch devices from server
  102. if (![JDFacade facade].loginUser.homehubDeviceId || [[JDFacade facade].loginUser.homehubDeviceId isEmptyString]) {
  103. [_mainView bringSubviewToFront:_addHubContainerView];
  104. _collectionView.hidden = YES;
  105. } else {
  106. [_mainView bringSubviewToFront:_collectionView];
  107. _addHubContainerView.hidden = YES;
  108. _collectionView.hidden = NO;
  109. [self performSelector:@selector(requestDeviceList) withObject:nil afterDelay:0.0f];
  110. }
  111. }
  112. - (void)updateHomeHubStatusToDevices {
  113. for (DeviceModel *device in _deviceList) {
  114. device.onlineState = [JDFacade facade].loginUser.homehubOnlineState;
  115. }
  116. [_collectionView reloadData];
  117. }
  118. - (void)updateDevice:(DeviceModel *)device {
  119. // if ([device.deviceId isEqualToString:ldevice.deviceId]) {
  120. // ldevice.cmdclsValue = device.cmdclsValue;
  121. // ldevice.contentValue = device.contentValue;
  122. // break;
  123. // }
  124. }
  125. - (void)requestPollingCommandStatusOfDeviceInBackground:(DeviceModel *)device {
  126. if (!_commandArray) {
  127. _commandArray = (NSMutableArray<DeviceModel> *)[[NSMutableArray alloc] init];
  128. }
  129. __block BOOL isStatusChanged = NO;
  130. if (device && [device isKindOfClass:[DeviceModel class]]) {//validate, aleady have,
  131. if (![_commandArray objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", device.deviceId, device.nodeId]) {//일치하는 디바이스가 있을 경우, 추가하지 않음.
  132. [_commandArray addObject:device];
  133. isStatusChanged = YES;
  134. }
  135. }
  136. //TODO : 추가 커맨드를 받을 것인가?
  137. if (_commandArray.count) {
  138. NSMutableString *pathParams = [[NSMutableString alloc] init];
  139. for (DeviceModel *pDevice in _commandArray) {
  140. NSString *prefix = [pathParams isEmptyString] ? ksEmptyString : @",";
  141. [pathParams appendFormat:@"%@%@_%@", prefix, pDevice.deviceId, pDevice.nodeId];
  142. }
  143. //20
  144. NSString *path = [NSString stringWithFormat:API_GET_DEVICE_NODE_STATUS, pathParams];
  145. dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{//RUN to background thread
  146. DeviceListModel *fdevices = [[RequestHandler handler] sendSyncGetRequestAPIPath:path parameters:nil
  147. modelClass:[DeviceListModel class] showLoadingView:YES];
  148. if (fdevices && fdevices.list && fdevices.list.count) {
  149. [_commandArray enumerateObjectsUsingBlock:^(DeviceModel *rdevice, NSUInteger idx, BOOL * _Nonnull stop) {
  150. DeviceModel *matchedDevice = (DeviceModel *)[fdevices.list objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", rdevice.deviceId, rdevice.nodeId];
  151. //실행 여부 및 20초 경과 확인
  152. BOOL isOverTimeLimit = [self elapsedSecondsFromNow:rdevice] > 20;
  153. //실행 여부 확인
  154. NSInteger elapsedTime = [self elapsedSecondsFrom:rdevice to:matchedDevice];
  155. BOOL hasChangedStatus = elapsedTime > 0;
  156. rdevice.isRequesting = [rdevice.contentValue isEqualToString:matchedDevice.contentValue] && !hasChangedStatus && !isOverTimeLimit;
  157. //TODO - home hub
  158. // rdevice.requestTime = matchedDevice.requestTime;
  159. // rdevice.collectTime = matchedDevice.collectTime;
  160. rdevice.onlineState = matchedDevice.onlineState;
  161. if (!rdevice.isRequesting || !rdevice.isOnline || ![JDFacade facade].loginUser.isHomehubOnline) {
  162. rdevice.contentValue = matchedDevice.contentValue;
  163. [_commandArray removeObject:rdevice];
  164. isStatusChanged = YES;
  165. }
  166. #ifdef DEBUG_MODE
  167. NSLogInfo(@"==########== device command status = %@, elapsedTime = %zd ==########==", [JDFacade facade].loginUser.homehubOnlineState, elapsedTime);
  168. #endif
  169. }];
  170. }
  171. if (_commandArray.count) {//커맨드 실행 중인 디바이스가 있을 경우,
  172. //schedul timer.
  173. if (!_deviceCommandsBackgroundTimer) {
  174. _deviceCommandsBackgroundTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(requestPollingCommandStatusOfDeviceInBackground:) userInfo:nil repeats:YES];
  175. }
  176. } else {
  177. [_deviceCommandsBackgroundTimer invalidate];
  178. _deviceCommandsBackgroundTimer = nil;
  179. }
  180. //변화가 있을 경우, 컬렉션뷰를 리로드
  181. if (isStatusChanged) {
  182. [_collectionView reloadData];
  183. }
  184. });
  185. }
  186. }
  187. - (NSInteger)elapsedSecondsFromNow:(DeviceModel *)runningDevice {
  188. NSInteger seconds = 0;
  189. if (runningDevice.requestTime && ![runningDevice.requestTime isEmptyString]) {
  190. NSDate *rdate = [CommonUtil dateFromDateString:[CommonUtil localDateFromUTC:runningDevice.requestTime]];
  191. NSTimeInterval elapsed = [[NSDate systemDate] timeIntervalSinceDate:rdate];
  192. seconds = elapsed;
  193. }
  194. return seconds;
  195. }
  196. - (NSInteger)elapsedSecondsFrom:(DeviceModel *)runningDevice to:(DeviceModel *)fetchedDevice {
  197. NSInteger seconds = 0;
  198. if (runningDevice.requestTime && ![runningDevice.requestTime isEmptyString] && fetchedDevice.collectTime && ![fetchedDevice.collectTime isEmptyString]) {
  199. NSDate *rdate = [CommonUtil dateFromDateString:[CommonUtil localDateFromUTC:runningDevice.requestTime]];
  200. NSDate *fdate = [CommonUtil dateFromDateString:[CommonUtil localDateFromUTC:fetchedDevice.collectTime]];
  201. seconds = [fdate secondsAfterDate:rdate];
  202. }
  203. return seconds;
  204. }
  205. - (void)addNewDevice {
  206. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddViewController" storyboardName:@"Things"];
  207. [self presentViewController:vc animated:YES completion:nil];
  208. }
  209. - (void)toggleEditMode {
  210. _isDeleteMode = !_isDeleteMode;
  211. [_collectionView reloadData];
  212. _constraintEditModeRight.constant = _isDeleteMode ? 0 : -_editModeView.width;
  213. [UIView animateWithDuration:kfAnimationDur animations:^{
  214. [self.view layoutIfNeeded];
  215. }];
  216. }
  217. - (void)refreshDeviceList {
  218. [self performSelector:@selector(requestDeviceList) withObject:nil afterDelay:0.0f];
  219. }
  220. #pragma mark - Main Logic
  221. - (void)requestDeviceListRecently {
  222. DeviceModel *firstDevice = [_deviceList firstObject];
  223. _pagingType = ksListPagingTypeUpward;
  224. _pagingId = firstDevice.createDatetime;
  225. [self performSelector:@selector(requestDeviceList) withObject:nil afterDelay:0.0f];
  226. }
  227. - (void)requestDeviceListOlder {
  228. DeviceModel *lastDevice = [_deviceList lastObject];
  229. _pagingType = ksListPagingTypeDownward;
  230. _pagingId = lastDevice.createDatetime;
  231. [self performSelector:@selector(requestDeviceList) withObject:nil afterDelay:0.0f];
  232. }
  233. - (void)requestDeviceList {
  234. //parameters
  235. NSDictionary *parameter = @{@"paging_datetime": _pagingId ? _pagingId : ksEmptyString,
  236. @"paging_type": _pagingType ? _pagingType : ksEmptyString};
  237. NSString *path = [NSString stringWithFormat:API_GET_DEVICE_LIST];
  238. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:parameter modelClass:[DeviceListModel class] completion:^(id responseObject) {
  239. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  240. return;
  241. }
  242. DeviceListModel *deviceList = (DeviceListModel *)responseObject;
  243. if (deviceList && deviceList.list && deviceList.list.count) {
  244. _deviceList = deviceList.list;
  245. _lblTitle.text = [NSString stringWithFormat:@"장치 전체 %zd", _deviceList.count];
  246. [_lblTitle setColor:kUITextColor02 text:[NSString stringWithFormat:@"%zd", _deviceList.count]];
  247. } else {
  248. if (!_deviceList.count) {//이미 로드된 데이터가 있을 경우는 출력하지 않음.
  249. // NoContentView *noContentView = [NoContentView viewFromNib];
  250. // _tableView.tableFooterView = noContentView;
  251. }
  252. }
  253. [self matchDeviceListWithOnCommandsDevices];
  254. } failure:^(id errorObject) {
  255. JDErrorModel *error = (JDErrorModel *)errorObject;
  256. [[JDFacade facade] alert:error.errorMessage];
  257. }];
  258. }
  259. - (void)matchDeviceListWithOnCommandsDevices {
  260. for (DeviceModel *rdevice in _commandArray) {
  261. DeviceModel *matchedDevice = [_deviceList objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", rdevice.deviceId, rdevice.nodeId]; //일치하는 디바이스가 있을 경우, 추가하지 않음.
  262. if (matchedDevice) {
  263. matchedDevice.isRequesting = rdevice.isRequesting;
  264. matchedDevice.requestTime = rdevice.requestTime;
  265. }
  266. }
  267. [_collectionView reloadData];
  268. }
  269. #pragma mark - UICollectionView Delegate
  270. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  271. NSInteger auth = [JDFacade facade].loginUser.level == 90 && !_isDeleteMode; //마스터 권한일 경우,
  272. NSInteger count = _deviceList.count % 2 == 0 ? _deviceList.count : _deviceList.count + auth; //홀수일 경우, 멤버 초대 버튼을 추가해줌.
  273. return count;
  274. }
  275. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  276. UICollectionViewCell *rcell = nil;
  277. if (indexPath.row < _deviceList.count) {
  278. ThingsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ThingsCellIdentifier" forIndexPath:indexPath];
  279. DeviceModel *device =_deviceList[indexPath.row];
  280. cell.indexPath = indexPath;
  281. [cell.btnDevice sd_setImageWithURL:[NSURL URLWithString:device.imageFileName] forState:UIControlStateNormal
  282. placeholderImage:nil
  283. options:SDWebImageRefreshCached
  284. completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  285. [cell layoutIfNeeded];
  286. }];
  287. cell.lblDeviceName.text = device.deviceName;
  288. //커맨드 클래스 뷰를 초기화함.
  289. [[cell.controlContainer subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  290. UIView *subview = (UIView *)obj;
  291. [subview removeFromSuperview];
  292. }];
  293. cell.btnDelete.hidden = !_isDeleteMode;
  294. cell.controlContainer.hidden = _isDeleteMode;
  295. cell.aiv.hidden = !device.isRequesting;
  296. if (!cell.aiv.hidden) {//show
  297. [cell.aiv startAnimating];
  298. cell.btnDelete.userInteractionEnabled = NO;
  299. } else {//hide
  300. [cell.aiv stopAnimating];
  301. cell.btnDelete.userInteractionEnabled = YES;
  302. }
  303. if (!cell.controlContainer.hidden) {
  304. //허브 On-Off line check
  305. cell.lblDeviceStatus.hidden = !([[JDFacade facade].loginUser.homehubOnlineState isEqualToString:@"OFF"] || [device.onlineState isEqualToString:@"OFF"]);
  306. cell.controlContainer.hidden = !cell.lblDeviceStatus.hidden;
  307. if (cell.controlContainer.hidden) {
  308. cell.lblDeviceStatus.text = @"OFFLINE";
  309. } else {//커맨드 클래스 타입별 컨트롤 호출
  310. CommandClassControlView *controlView = [CommandClassControlView viewForCommandClass:device.cmdclsType];
  311. controlView.device = device;
  312. cell.controlContainer.hidden = !controlView;
  313. if (!cell.controlContainer.hidden) {
  314. UIView *superview = cell.controlContainer;
  315. [superview addSubview:controlView];
  316. [controlView mas_makeConstraints:^(MASConstraintMaker *make) {
  317. make.size.mas_equalTo(controlView.frame.size);
  318. make.center.equalTo(superview);
  319. }];
  320. }
  321. }
  322. } else {
  323. cell.btnDelete.value = device;
  324. if (![cell.btnDelete actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  325. [cell.btnDelete addTarget:self action:@selector(btnDeleteTouched:) forControlEvents:UIControlEventTouchUpInside];
  326. }
  327. }
  328. rcell = cell;
  329. } else {//디바이스 추가 옵션
  330. ThingsAddCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AddCollectionCellIdentifier" forIndexPath:indexPath];
  331. if (![cell.btnAdd actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  332. [cell.btnAdd addTarget:self action:@selector(addNewDevice) forControlEvents:UIControlEventTouchUpInside];
  333. }
  334. rcell = cell;
  335. }
  336. return rcell;
  337. }
  338. - (void)btnDeleteTouched:(id)sender {
  339. CustomButton *btn = (CustomButton *)sender;
  340. DeviceModel *device = (DeviceModel *)btn.value;
  341. ThingsAddStartViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddStartViewController" storyboardName:@"Things"];
  342. vc.removableDevice = device;
  343. if (device.groupName && ![device.groupName isEmptyString]) {
  344. vc.removableGroups = [_deviceList filteredArrayUsingPredicateFormat:@"groupName == %@", device.groupName]; //group devices
  345. }
  346. vc.providesPresentationContextTransitionStyle = YES;
  347. vc.definesPresentationContext = YES;
  348. [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
  349. [self presentViewController:vc animated:NO completion:nil];
  350. }
  351. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
  352. viewForSupplementaryElementOfKind:(NSString *)kind
  353. atIndexPath:(NSIndexPath *)indexPath
  354. {
  355. ThingsCollectionFooterView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter
  356. withReuseIdentifier:@"FooterIdentifier" forIndexPath:indexPath];
  357. if (![footerView.btnAdd actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  358. [footerView.btnAdd addTarget:self action:@selector(addNewDevice) forControlEvents:UIControlEventTouchUpInside];
  359. }
  360. return footerView;
  361. }
  362. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
  363. //FIXME : 권한 추가
  364. // if (_memberList.count % 2 == 1 || [JDFacade facade].loginUser.level < 90 || _isDeleteMode) {//마스터 권한이 아니거나, 짝수가 아닐 경우
  365. if (_deviceList.count % 2 == 1 || _isDeleteMode) {//마스터 권한이 아니거나, 짝수가 아닐 경우
  366. return CGSizeZero;
  367. }
  368. return CGSizeMake(IPHONE_WIDTH, 160.0f);
  369. }
  370. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  371. if (IPHONE_WIDTH == 414.0f) {//아이폰 6일 경우,
  372. return CGSizeMake(212.0f, 197.0f);
  373. } else if (IPHONE_WIDTH == 375.0f) {//아이폰 6+일경우
  374. return CGSizeMake(187.5, 197.0f);
  375. }
  376. return CGSizeMake(160.0f, 197.0f);
  377. }
  378. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  379. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  380. if (indexPath.row < _deviceList.count) {
  381. ThingsCollectionViewCell *cell = (ThingsCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"ThingsCellIdentifier" forIndexPath:indexPath];
  382. DeviceModel *device = _deviceList[indexPath.row];
  383. }
  384. }
  385. #pragma mark - UI Events
  386. - (void)btnAddHubTouched:(id)sender {
  387. [[JDFacade facade] gotoHomeHubRegistration];
  388. }
  389. - (IBAction)btnOptionTouched:(id)sender {
  390. [self toggleOptions:sender];
  391. }
  392. - (IBAction)btnCloseOnEditModeTouched:(id)sender {
  393. [self toggleEditMode];
  394. }
  395. #pragma mark - MemoryWarning
  396. - (void)viewWillDisappear:(BOOL)animated {
  397. if (_deviceCommandsBackgroundTimer) {
  398. [_deviceCommandsBackgroundTimer invalidate];
  399. _deviceCommandsBackgroundTimer = nil;
  400. }
  401. }
  402. - (void)didReceiveMemoryWarning
  403. {
  404. [super didReceiveMemoryWarning];
  405. // Dispose of any resources that can be recreated.
  406. }
  407. @end