demo
来源:互联网 发布:软件项目成功案例 编辑:程序博客网 时间:2024/06/13 13:18
Z2#import "BrowserViewController.h" 3#include <arpa/inet.h> 4#import <SystemConfiguration/SystemConfiguration.h> 5#import <SystemConfiguration/CaptiveNetwork.h> 6#import "HistoryViewController.h" 7#import "GenieModuleHelper.h" 8#import "BonjourServiceResolving.h" 9#import "GenieHelper.h" 10#import "GenieHelper_Statistics.h" 11#import "UDTDelegation.h" 12#import "BonjourTest.h" 13#import <AVFoundation/AVFoundation.h> 14#include <MobileCoreServices/MobileCoreServices.h> 15//#import "AVURLAsset.h" 16#import "DLNADelegation.h" 17#import "DLNACore.h" 18#import "UIImage+UIImageExt.h" 19#import "TextMessageViewController.h" 20#import "CheckButton.h" 21 22#define kProgressIndicatorSize 20.0 23 24// A category on NSNetService that's used to sort NSNetService objects by their name. 25@interface NSNetService (BrowserViewControllerAdditions) 26- (NSComparisonResult) localizedCaseInsensitiveCompareByName:(NSNetService *)aService; 27@end 28 29@implementation NSNetService (BrowserViewControllerAdditions) 30- (NSComparisonResult) localizedCaseInsensitiveCompareByName:(NSNetService *)aService { 31 return [[self name] localizedCaseInsensitiveCompare:[aService name]]; 32} 33@end 34 35 36@interface BrowserViewController() 37@property (nonatomic, retain, readwrite) NSNetService *ownEntry; 38@property (nonatomic, assign, readwrite) BOOL showDisclosureIndicators; 39@property (nonatomic, retain, readwrite) NSMutableArray *services; 40@property (nonatomic, retain, readwrite) NSNetServiceBrowser *netServiceBrowser; 41@property (nonatomic, retain, readwrite) NSNetService *currentResolve; 42@property (nonatomic, retain, readwrite) NSTimer *timer; 43@property (nonatomic, assign, readwrite) BOOL needsActivityIndicator; 44@property (nonatomic, assign, readwrite) BOOL initialWaitOver; 45 46@property(nonatomic)class UDTDelegation *delegation; 47 48- (void)stopCurrentResolve; 49- (void)initialWaitOver:(NSTimer *)timer; 50@end 51 52@implementation BrowserViewController 53 54@synthesize delegate = _delegate; 55@synthesize ownEntry = _ownEntry; 56@synthesize showDisclosureIndicators = _showDisclosureIndicators; 57@synthesize currentResolve = _currentResolve; 58@synthesize netServiceBrowser = _netServiceBrowser; 59@synthesize services = _services; 60@synthesize needsActivityIndicator = _needsActivityIndicator; 61@dynamic timer; 62@synthesize initialWaitOver = _initialWaitOver; 63 64@synthesize delegation = _delegation; 65@synthesize m_alert = m_alert; 66 67- (void) loadView 68{ 69 UIView * v = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 70 self.view = v; 71 [v release]; 72 [self.view setBackgroundColor:[UIColor blackColor]]; 73 74 //hi.tan: ios5,6,7 同一导航栏:添加一个刷新按钮,ios7用系统的,ios 5,6用图片自定义 75// if([UIDevice currentDevice].systemVersion.floatValue >= 7.0) 76// { 77// UIBarButtonItem * rightBtnItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(savingPowerModeSetting)]; 78// self.navigationItem.rightBarButtonItem = rightBtnItem; 79// [rightBtnItem release]; 80// } 81// else 82// { 83// //hi.tan:IOS6上用图片来显示 84// UIImage *tmpimage = [UIImage imageNamed:@"refresh.png"]; 85// UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 26, 26)]; 86// [btn setBackgroundImage:tmpimage forState:UIControlStateNormal]; 87// [btn addTarget:self action:@selector(savingPowerModeSetting) forControlEvents:UIControlEventTouchUpInside]; 88// UIBarButtonItem * rightBtnItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; 89// self.navigationItem.rightBarButtonItem = rightBtnItem; 90// [rightBtnItem release]; 91// [btn release]; 92// } 93 94 UIBarButtonItem * rightBtnItem = [[UIBarButtonItem alloc] initWithTitle:Localization_Wireless_InfoPage_Title style: UIBarButtonItemStylePlain target:self action:@selector(savingPowerModeSetting)]; 95 self.navigationItem.rightBarButtonItem = rightBtnItem; 96 [rightBtnItem release]; 97 //hi.tan: ios5,6,7 同一导航栏:添加一个刷新按钮,ios7用系统的,ios 5,6用图片自定义 98 99 //wifi显示视图: edited by hi.tan: 屏幕旋转ui的处理 100 m_wifiView = [[UIView alloc] initWithFrame:CGRectZero]; 101 102 if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) 103 { 104 m_wifiView.frame = CGRectMake(CGZero, CGZero, iOSDeviceScreenWidth, 30); 105 } 106 else if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) 107 { 108 m_wifiView.frame = CGRectMake(CGZero, CGZero, iOSDeviceScreenHeight, 30); 109 } 110 111 //添加label到views 112 m_wifilab = [[UILabel alloc]initWithFrame:CGRectMake(45, 5, 150, 20)]; 113 NSString *wifiName = [self getwifiName]; 114 //添加wifi图标 115 UIImageView *wifiImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, 20, 20)]; 116 if([wifiName isEqualToString:Localization_Mobile_Device_WIFI_NotEnable]) 117 { 118 wifiImage.image = [UIImage imageNamed:@"signal_level_0.png"]; 119 } 120 else 121 { 122 wifiImage.image = [UIImage imageNamed:@"signal_level_4.png"]; 123 } 124 [m_wifiView addSubview:wifiImage]; 125 [wifiImage release]; 126 127 m_wifilab.text = wifiName; 128 m_wifilab.font = [UIFont systemFontOfSize:12.0]; 129 m_wifilab.textColor = [UIColor whiteColor]; 130 m_wifilab.backgroundColor = [UIColor clearColor]; 131 [m_wifiView addSubview:m_wifilab]; 132 133 m_wifiView.backgroundColor = [UIColor grayColor]; 134 // [views setAlpha:0.5]; 135 [self.view addSubview:m_wifiView]; 136 137 138 139 self.title = Localization_HP_Turbo_Transfer_Function_DeviceList_Title; 140 141 //toolbar视图: edited by hi.tan : 屏幕旋转处理 142 m_toolView = [[UIView alloc] initWithFrame:CGRectZero]; 143 if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) 144 { 145 m_toolView.frame = CGRectMake(CGZero, iOSDeviceScreenHeight-iOSStatusBarHeight-Navi_Bar_Height_Portrait - 50, iOSDeviceScreenWidth, 50); 146 } 147 else if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) 148 { 149 m_toolView.frame = CGRectMake(CGZero, iOSDeviceScreenWidth-iOSStatusBarHeight-Navi_Bar_Height_Landscape - 50, iOSDeviceScreenHeight, 50); 150 } 151 152 153 [m_toolView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"0.png"]]]; 154 [self.view addSubview:m_toolView]; 155 156 m_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 48, 48)]; 157 m_imageView.image = [UIImage imageNamed:@"one.png"]; 158 //imageview绑定点击事件 159 m_imageView.userInteractionEnabled=YES; 160 UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage)]; 161 [m_imageView addGestureRecognizer:singleTap]; 162 [singleTap release]; 163 [m_toolView addSubview:m_imageView]; 164 //得到设备名称 165 UILabel *deviceLab = [[UILabel alloc] initWithFrame:CGRectMake(60, 5, 200, 40)]; 166 deviceLab.textColor = [UIColor whiteColor]; 167 deviceLab.backgroundColor = [UIColor clearColor]; 168 deviceLab.text = [[UIDevice currentDevice] name]; 169 [m_toolView addSubview:deviceLab]; 170 [deviceLab release]; 171 172 m_hosBtn = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; 173 m_hosBtn.frame= CGRectZero; 174 // add by hi.tan: 屏幕旋转处理 175 if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){ 176 m_hosBtn.frame= CGRectMake(iOSDeviceScreenWidth - 32 - 6 , 5, 32, 30); 177 } 178 else if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){ 179 m_hosBtn.frame= CGRectMake(iOSDeviceScreenHeight - 32 - 6, 5, 32, 30); 180 } 181 // 182 [m_hosBtn setBackgroundImage:[UIImage imageNamed:@"turbo_history_small.png"] forState:UIControlStateNormal]; 183 [m_hosBtn addTarget:self action:@selector(showHistoryView) forControlEvents:UIControlEventTouchUpInside]; 184 [m_toolView addSubview:m_hosBtn]; 185 186 //edited by hi.tan: 屏幕旋转处理 187 //m_hisLab = [[UILabel alloc] initWithFrame:CGRectMake(283, 30, 25, 15)]; 188 m_hisLab = [[UILabel alloc] initWithFrame:CGRectZero]; 189 if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){ 190 m_hisLab.frame= CGRectMake(iOSDeviceScreenWidth - 42, 33, 40, 15); 191 } 192 else if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){ 193 m_hisLab.frame= CGRectMake(iOSDeviceScreenHeight - 42, 33, 40, 15); 194 } 195 196 m_hisLab.backgroundColor = [UIColor clearColor]; 197 m_hisLab.text = Localization_HP_Turbo_Transfer_Function_History_Title; 198 m_hisLab.font = [UIFont systemFontOfSize:10.0]; 199 m_hisLab.textColor =[UIColor whiteColor]; 200 m_hisLab.textAlignment = NSTextAlignmentCenter; 201 [m_toolView addSubview:m_hisLab]; 202 203 [self tableViewData]; 204 [m_tableView reloadData]; 205 206} 207 208//hi.tan: 更新wifi名称 209-(void)updateWifiNameLabel 210{ 211#ifdef __GENIE_IPHONE__ 212 GenieiPhoneiPodAppDelegate *appDelegate = (GenieiPhoneiPodAppDelegate *)[UIApplication sharedApplication].delegate; 213#else 214 GenieiPadAppDelegate *appDelegate = (GenieiPadAppDelegate *)[UIApplication sharedApplication].delegate; 215#endif 216 217 NSString *WIFI_SSID = [appDelegate getCurrentWIFI_SSID]; 218 m_wifilab.text = WIFI_SSID;//[self getwifiName]; 219 220 [m_tableView reloadData]; 221} 222 223 224-(void)viewDidLoad 225{ 226 [super viewDidLoad]; 227 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) 228 { 229 /* 230 增加iOS 7适配。 231 232 2013-10-10 by 梁平贤 233 */ 234 self.edgesForExtendedLayout = UIRectEdgeNone; 235 } 236 //[self WaitMessageDialogShow:Localization_FileTransfer_Wait_Msg]; 237 //[self onClickImage]; 238 239 //注册一个切换wifi更新wifi名称的通知 240 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateWifiNameLabel) name:@"updateWifiName" object:nil]; 241 //hi.tan: 下拉刷新功能 242 if (_refreshHeaderView == nil) { 243 244 EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:m_tableView.bounds]; 245 246 //上移 247 CGPoint center=view.center; 248 center.y-=m_tableView.bounds.size.height; 249 view.center=center; 250 251 view.delegate = self; 252 [m_tableView addSubview:view]; 253 _refreshHeaderView = view; 254 [view release]; 255 256 } 257 // update the last update date 258// [_refreshHeaderView refreshLastUpdatedDate]; 259// NSDate* date = [_refreshHeaderView getDateTime]; 260// m_lasttime = [date timeIntervalSince1970]*1; 261 //第一次进来,就进行刷新 262 m_tableView.contentOffset = CGPointMake(0, -65); 263 [_refreshHeaderView egoRefreshScrollViewDidEndDragging:m_tableView]; 264 [_refreshHeaderView egoRefreshScrollViewDidScroll:m_tableView]; 265 266 //hi.tan: 下拉刷新功能 267 //hi.tan: 检测文件传输端口是否监听成功 268 //[[GenieHelper GetInstance] newFileTransferPortListen]; 269} 270 271- (void)viewDidUnload 272{ 273 _refreshHeaderView=nil; 274} 275 276#pragma mark - 277#pragma mark Data Source Loading / Reloading Methods 278 279- (void)reloadTableViewDataSource{ 280 281 // should be calling your tableviews data source model to reload 282 // put here just for demo 283 284 [self refreshDeviceList]; 285 _reloading = YES; 286 287} 288 289- (void)doneLoadingTableViewData{ 290 291 // model should call this when its done loading 292 _reloading = NO; 293 [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:m_tableView]; 294 295} 296 297 298#pragma mark - 299#pragma mark UIScrollViewDelegate Methods 300 301- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ 302 303 [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView]; 304 305} 306 307- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ 308 309 [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView]; 310 311} 312 313 314#pragma mark - 315#pragma mark EGORefreshTableHeaderDelegate Methods 316 317- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view 318{ 319 [self reloadTableViewDataSource]; 320 [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0]; 321} 322 323- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{ 324 325 return _reloading; // should return if data source model is reloading 326 327} 328 329- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{ 330 331 return [NSDate date]; // should return date data source was last changed 332 333} 334#pragma mark EGORefreshTableHeaderDelegate Methods 335 336 337-(void)WaitMessageDialogShow:(NSString *)msg 338{ 339 if (m_alert != nil) 340 { 341 [m_alert release]; 342 m_alert = nil; 343 } 344 345 346 m_alert = [[[UIAlertView alloc] initWithTitle:msg 347 message:nil 348 delegate:self 349 cancelButtonTitle:nil 350 otherButtonTitles: nil] autorelease]; 351 [m_alert setFrame:CGRectMake(self.view.frame.size.width / 2 - 20, self.view.frame.size.height /2 - 60, 280, 120)]; 352 353 [m_alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES]; 354 355 UIActivityIndicatorView * aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 356 aiv.center = CGPointMake(m_alert.bounds.size.width/2.0f, m_alert.bounds.size.height/2.0f + 16); 357 [aiv startAnimating]; 358 [m_alert addSubview:aiv]; 359 [aiv release]; 360 361 [self performSelectorOnMainThread:@selector(dismissMyAlert) withObject:nil waitUntilDone:YES]; 362} 363 364- (void) dismissMyAlert 365{ 366 if(m_alert != nil) 367 { 368 [m_alert dismissWithClickedButtonIndex:99 animated:YES]; 369 m_alert = nil; 370 } 371} 372 373- (id)initWithTitle:(NSString *)title showDisclosureIndicators:(BOOL)show showCancelButton:(BOOL)showCancelButton { 374 375 m_alert = nil; 376// if ((self = [super initWithStyle:UITableViewStylePlain])) { 377 self.currentResolve = [[NSNetService alloc] init]; 378 self.title = title; 379 _services = [[NSMutableArray alloc] init]; 380 self.showDisclosureIndicators = show; 381 if (showCancelButton) { 382 // add Cancel button as the nav bar's custom right view 383 UIBarButtonItem *addButton = [[UIBarButtonItem alloc] 384 initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAction)]; 385 self.navigationItem.rightBarButtonItem = addButton; 386 [addButton release]; 387 } 388 389 // Make sure we have a chance to discover devices before showing the user that nothing was found (yet) 390 [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(initialWaitOver:) userInfo:nil repeats:NO]; 391// } 392 //bonjour service updated by self or DLNA 393 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bonjourServersUpdate:) name:@"BonjourChange" object:nil]; 394 [self.currentResolve release]; 395 return self; 396} 397 398 399// hi.tan: 添加修改对屏幕旋转的处理 400- (void) viewWillAppear:(BOOL)animated 401{ 402 [super viewWillAppear:animated]; 403 [self showViewWithOrientation:self.interfaceOrientation]; 404} 405 406- (BOOL)shouldAutorotate 407{ 408 return YES; 409} 410- (NSUInteger)supportedInterfaceOrientations 411{ 412 return UIInterfaceOrientationMaskAll; 413} 414 415- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 416{ 417 return YES; 418} 419 420- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 421{ 422 [self showViewWithOrientation:toInterfaceOrientation]; 423} 424- (void) showViewWithOrientation:(UIInterfaceOrientation)orientation 425{ 426 427 //tableView frame.size.y = 30: 为上面的无线标签留出来的 428 //高度减去50,是为底部的toolbar留出空间 429 if (UIInterfaceOrientationIsPortrait(orientation)) 430 { 431 m_tableView.frame = CGRectMake(CGZero, 30, iOSDeviceScreenWidth, iOSDeviceScreenHeight-iOSStatusBarHeight-Navi_Bar_Height_Portrait - 50 -30); 432 m_toolView.frame = CGRectMake(CGZero, iOSDeviceScreenHeight-iOSStatusBarHeight-Navi_Bar_Height_Portrait - 50, iOSDeviceScreenWidth, 50); 433 m_wifiView.frame = CGRectMake(CGZero, CGZero, iOSDeviceScreenWidth, 30); 434 m_hosBtn.frame= CGRectMake(iOSDeviceScreenWidth - 32-6, 5, 32, 30); 435 m_hisLab.frame= CGRectMake(iOSDeviceScreenWidth - 42, 33, 40, 15); 436 } 437 else if (UIInterfaceOrientationIsLandscape(orientation)) 438 { 439 m_tableView.frame = CGRectMake(CGZero, 30, iOSDeviceScreenHeight, iOSDeviceScreenWidth-iOSStatusBarHeight-Navi_Bar_Height_Landscape - 50 -30); 440 m_toolView.frame = CGRectMake(CGZero, iOSDeviceScreenWidth-iOSStatusBarHeight-Navi_Bar_Height_Landscape - 50, iOSDeviceScreenHeight, 50); 441 m_wifiView.frame = CGRectMake(CGZero, CGZero, iOSDeviceScreenHeight, 30); 442 m_hosBtn.frame= CGRectMake(iOSDeviceScreenHeight - 32-6, 5, 32, 30); 443 m_hisLab.frame= CGRectMake(iOSDeviceScreenHeight - 42, 33, 40, 15); 444 } 445 446} 447// hi.tan: 添加修改对屏幕旋转的处理 448 449 450// 右上角添加的刷新按钮 451-(void)refreshDeviceList 452{ 453 //2014-4-21: 做一下监测,发现当前上层ui没有设备的时候,就只需要去搜索设备就ok了 454 if([[[BonjourServiceResolving GetBonjourResolvInstance] getIPArray] count] != 0) 455 { 456 [[BonjourServiceResolving GetBonjourResolvInstance] deleteAllDeviceList]; 457 //HI.tan: 2014-4-10: 刷新按钮将DLNA设备发现的底层保存的设备一同给删除掉 458 DLNADelegation::GetInstance()->refreshDevices((deejay::DLNACore::FlushMode)0); 459 } 460 DLNADelegation::GetInstance()->searchDevices(); 461 [[BonjourServiceResolving GetBonjourResolvInstance] searchForServicesOfType:@"_ros-master._tcp" inDomain:@"local"]; 462} 463 464 465-(void)savingPowerModeSetting 466{ 467 468// m_tableView.contentOffset = CGPointMake(0, -65); 469// [_refreshHeaderView egoRefreshScrollViewDidEndDragging:m_tableView]; 470// [_refreshHeaderView egoRefreshScrollViewDidScroll:m_tableView]; 471// return; 472 473 474 if([UIDevice currentDevice].systemVersion.floatValue >= 7.0) 475 { 476 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil 477 message:NSLocalizedString(@"Enable Power Saving Mode Message",nil) 478 delegate:self 479 cancelButtonTitle:nil 480 otherButtonTitles:Localization_Close,nil]; 481 482 UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 260, 40)]; 483 bgView.backgroundColor = [UIColor clearColor]; 484 485 CheckButton *checkButton = [[CheckButton alloc ] initWithFrame : CGRectMake (22, 0, 240, 32)]; 486 checkButton.value =[[ NSNumber alloc ] initWithInt:1]; 487 // 把按钮设置为单选按钮样式 488 checkButton. style = CheckButtonStyleBox; 489 checkButton.checked = [GenieHelper getSavingPowerModeFlag]; 490 checkButton.enabled = YES; 491 checkButton.label.text = NSLocalizedString(@"Enable Power Saving Mode",nil); 492 checkButton.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14]; 493 checkButton.label.textColor = [UIColor blackColor]; 494 checkButton.delegate = self; 495 [bgView addSubview:checkButton]; 496 [alert setValue:bgView forKey:@"accessoryView"]; 497 [checkButton release]; 498 [bgView release]; 499 [alert show]; 500 [alert release]; 501 } 502 else 503 { 504 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"\n\n" 505 message:NSLocalizedString(@"Enable Power Saving Mode Message",nil) 506 delegate:self 507 cancelButtonTitle:nil 508 otherButtonTitles:Localization_Close,nil]; 509 510 UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 12, 260, 40)]; 511 bgView.backgroundColor = [UIColor clearColor]; 512 513 CheckButton *checkButton = [[CheckButton alloc ] initWithFrame : CGRectMake (22, 0, 240, 32)]; 514 checkButton.value =[[ NSNumber alloc ] initWithInt:1]; 515 // 把按钮设置为单选按钮样式 516 checkButton. style = CheckButtonStyleBox; 517 checkButton.checked = [GenieHelper getSavingPowerModeFlag]; 518 checkButton.enabled = YES; 519 checkButton.label.text = NSLocalizedString(@"Enable Power Saving Mode",nil); 520 checkButton.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14]; 521 checkButton.label.textColor = [UIColor whiteColor]; 522 checkButton.delegate = self; 523 [bgView addSubview:checkButton]; 524 [alert addSubview:bgView]; 525 [checkButton release]; 526 [bgView release]; 527 [alert show]; 528 [alert release]; 529 } 530} 531 532 533//hi.tan: 省电模式的check按钮后需要在这里做处理,通过GenieHelper保存到本地,作为全局变量攻其它地方使用 534-(void)checkButtonClicked:(CheckButton *)button 535{ 536 CheckButton *btn = button; 537 if([btn checked]) 538 {8af249539#ifdef UserBehaviourZ540 [GenieAdvanceInfoStatistics GetInstance].turboTransfer.TT6++; 541#endif 542 543 291400544 [btn setChecked:NO];Z545 [GenieHelper setSavingPowerModeFlag:[btn checked]]; 546 //NSLog(@"Bool Checked = %d",[btn checked]); 547 } 548 else 549 {8af249550#ifdef UserBehaviourZ551 [GenieAdvanceInfoStatistics GetInstance].turboTransfer.TT5++; 552#endif291400553 [btn setChecked:YES];Z554 [GenieHelper setSavingPowerModeFlag:[btn checked]]; 555 //NSLog(@"Bool Checked = %d",[btn checked]); 556 } 557} 558 559// 当检测到bonjour服务或者DLNA服务的时候,即当bonReslv中的—IP_arry被更新的时候,同时更新这边tableview的数据 560- (void)bonjourServersUpdate:(NSNotification *)no 561{ 562 [m_tableView reloadData]; 563} 564 565- (void)turboTransferDeviceListUpdate 566{ 567 [m_tableView reloadData]; 568} 569 570 571- (NSString *)searchingForServicesString { 572 return _searchingForServicesString; 573} 574 575// Holds the string that's displayed in the table view during service discovery. 576- (void)setSearchingForServicesString:(NSString *)searchingForServicesString 577{ 578 if (_searchingForServicesString != searchingForServicesString) { 579 [_searchingForServicesString release]; 580 _searchingForServicesString = [searchingForServicesString copy]; 581 582 // If there are no services, reload the table to ensure that searchingForServicesString appears. 583 if ([self.services count] == 0) { 584 [m_tableView reloadData]; 585 } 586 } 587} 588 589- (NSString *)ownName 590{ 591 return _ownName; 592} 593 594// Holds the string that's displayed in the table view during service discovery. 595- (void)setOwnName:(NSString *)name { 596 if (_ownName != name) { 597 _ownName = [name copy]; 598 599 if (self.ownEntry) 600 [self.services addObject:self.ownEntry]; 601 602 NSNetService* service; 603 604 for (service in self.services) { 605 if ([service.name isEqual:name]) { 606 self.ownEntry = service; 607 [_services removeObject:service]; 608 609 break; 610 } 611 } 612 613 [m_tableView reloadData]; 614 } 615} 616 617- (NSTimer *)timer { 618 return _timer; 619} 620 621// When this is called, invalidate the existing timer before releasing it. 622- (void)setTimer:(NSTimer *)newTimer { 623 [_timer invalidate]; 624 [newTimer retain]; 625 [_timer release]; 626 _timer = newTimer; 627} 628 629- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 630 return 1; 631} 632 633- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 634 //NSUInteger count = [self.services count]; 635 NSUInteger count = [[[BonjourServiceResolving GetBonjourResolvInstance] getIPArray] count]; 636 637 if (count == 0 && self.searchingForServicesString && self.initialWaitOver) 638 return 1; 639 640 return count; 641} 642 643- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 644{ 645#ifdef __GENIE_IPHONE__ 646 return 49; 647#else 648 return 55; 649#endif 650} 651 652- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 653 654 static NSString *tableCellIdentifier = @"UITableViewCell"; 655 UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:tableCellIdentifier]; 656 if (cell == nil) { 657 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableCellIdentifier] autorelease]; 658 } 659 660 // ios7 默认背景颜色为白色 661 cell.backgroundColor = [UIColor clearColor]; 662 663 //NSUInteger count = [self.services count]; 664 NSMutableArray *IParray = [NSMutableArray arrayWithArray:[[BonjourServiceResolving GetBonjourResolvInstance] getIPArray]]; 665 666 NSUInteger count = [IParray count]; 667 668 if (count == 0) 669 { 670 cell.textLabel.text = self.searchingForServicesString; 671 cell.textLabel.textColor = [UIColor whiteColor]; 672 cell.accessoryType = UITableViewCellAccessoryNone; 673 if (cell.accessoryView) 674 cell.accessoryView = nil; 675 return cell; 676 } 677 // Set up the text for the cell 678 NSDictionary *dic = nil; 679 if(indexPath.row < count) 680 { 681 dic = [IParray objectAtIndex:indexPath.row]; 682 } 683 684 if(dic == nil) 685 { 686 cell.textLabel.text = self.searchingForServicesString; 687 cell.textLabel.textColor = [UIColor whiteColor]; 688 cell.accessoryType = UITableViewCellAccessoryNone; 689 if (cell.accessoryView) 690 cell.accessoryView = nil; 691 return cell; 692 } 693 694 NSString *ipstring = [dic objectForKey:@"ipAddr"]; 695 cell.detailTextLabel.text = ipstring; 696 cell.detailTextLabel.textColor = [UIColor whiteColor]; 697 698 NSString *serviceName = [dic objectForKey:@"serviceName"]; 699 NSString *serviceNameToDisplay = serviceName; 700 701 702// if([serviceNameToDisplay length] > 20) 703// { 704// //serviceName __NSCFString * @"“pingxian_liang”的 iPod[iPodtouch]" 0x16017cf0 705// 706// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"_" withString:@""]; 707// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@" " withString:@""]; 708// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"." withString:@"["]; 709// 710// //int index = serviceName 711// NSRange range; 712// memset(&range,0,sizeof(range)); 713// range = [serviceNameToDisplay rangeOfString:@"["]; 714// 715// if(range.location != 0 && range.location <= [serviceNameToDisplay length]) 716// { 717// serviceNameToDisplay = [serviceNameToDisplay substringToIndex:range.location]; 718// } 719// 720// if([serviceNameToDisplay length] > 20) 721// { 722// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"-" withString:@"["]; 723// NSRange range; 724// memset(&range,0,sizeof(range)); 725// range = [serviceNameToDisplay rangeOfString:@"["]; 726// 727// if(range.location != 0 && range.location <= [serviceNameToDisplay length]) 728// { 729// serviceNameToDisplay = [serviceNameToDisplay substringToIndex:range.location]; 730// } 731// } 732// 733// if([serviceNameToDisplay length] > 20) 734// { 735// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"_" withString:@""]; 736// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@" " withString:@""]; 737// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"." withString:@""]; 738// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"\"" withString:@""]; 739// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"\"" withString:@""]; 740// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"“" withString:@""]; 741// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"”" withString:@""]; 742// } 743// 744// if([serviceNameToDisplay length] >= 21) 745// { 746// serviceNameToDisplay = [serviceNameToDisplay substringToIndex:20]; 747// } 748// } 749 750 751 NSRange range = [serviceNameToDisplay rangeOfString:@"["]; 752 if(range.location > 0 && range.location <= [serviceNameToDisplay length]) 753 { 754 serviceNameToDisplay = [serviceNameToDisplay substringToIndex:range.location]; 755 } 756 757 cell.textLabel.text = serviceNameToDisplay; 758 cell.textLabel.textColor = [UIColor whiteColor]; 759 cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold"size:20]; //加粗 760 761 762 763 764 //cell.imageView.image = [UIImage imageNamed:@"defaultserver.png"]; //device_iphone_icon.png 765 NSString *serviceNameLowcase = [serviceName lowercaseString]; 766 UIImage *image = nil; 767 if ([serviceNameLowcase rangeOfString:@"iphone"].length) 768 { 769 image = [UIImage imageNamed:@"device_iphone_icon.png"]; 770 } 771 else if ([serviceNameLowcase rangeOfString:@"ipad"].length) 772 { 773 image = [UIImage imageNamed:@"device_ipad_icon.png"]; 774 } 775 else if ([serviceNameLowcase rangeOfString:@"ipod"].length) 776 { 777 image = [UIImage imageNamed:@"device_ipod_icon.png"]; 778 } 779 else if ([serviceNameLowcase rangeOfString:@"androidtablet"].length) 780 { 781 image = [UIImage imageNamed:@"device_androidtablet_icon.png"]; 782 } 783 else if ([serviceNameLowcase rangeOfString:@"androidphone"].length) 784 { 785 image = [UIImage imageNamed:@"device_androidphone_icon.png"]; 786 } 787 else if ([serviceNameLowcase rangeOfString:@"androiddevice"].length) 788 { 789 image = [UIImage imageNamed:@"device_androiddevice_icon.png"]; 790 } 791 else if ([serviceNameLowcase rangeOfString:@"mac-mini"].length) 792 { 793 image = [UIImage imageNamed:@"device_imac_icon.png"]; 794 } 795 else if ([serviceNameLowcase rangeOfString:@"imac-mini"].length) 796 { 797 image = [UIImage imageNamed:@"device_macmini_icon.png"]; 798 } 799 else if ([serviceNameLowcase rangeOfString:@"imac"].length) 800 { 801 image = [UIImage imageNamed:@"device_imac_icon.png"]; 802 } 803 else if ([serviceNameLowcase rangeOfString:@"window"].length) 804 { 805 image = [UIImage imageNamed:@"device_windowspc_icon.png"]; 806 } 807 else if ([serviceNameLowcase rangeOfString:@"amazonkindle"].length) 808 { 809 image = [UIImage imageNamed:@"device_kindle_icon.png"]; 810 } 811 else 812 { 813 NSData *data = UIImagePNGRepresentation([UIImage imageNamed:@"defaultserver.png"]); 814 image = (UIImage *)[ UIImage imageWithData:data scale:(CGFloat)40/72]; 815 816 //image = [UIImage imageNamed:@"defaultserver.png"]; 817 818 } 819 820 if(image == nil) 821 { 822 823 //image = [UIImage imageNamed:@"defaultserver.png"]; 824 NSData *data = UIImagePNGRepresentation([UIImage imageNamed:@"defaultserver.png"]); 825 image = (UIImage *)[ UIImage imageWithData:data scale:(CGFloat)40/72]; 826 } 827 828 829 //cell.imageView.image = image; 830 831// if (self.needsActivityIndicator /*&& self.currentResolve == service*/) { 832// if (!cell.accessoryView) { 833// CGRect frame = CGRectMake(0.0, 0.0, kProgressIndicatorSize, kProgressIndicatorSize); 834// UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithFrame:frame]; 835// [spinner startAnimating]; 836// spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; 837// [spinner sizeToFit]; 838// spinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | 839// UIViewAutoresizingFlexibleRightMargin | 840// UIViewAutoresizingFlexibleTopMargin | 841// UIViewAutoresizingFlexibleBottomMargin); 842// cell.accessoryView = spinner; 843// [spinner release]; 844// } 845// } else if (cell.accessoryView) { 846// cell.accessoryView = nil; 847// } 848 849 //NSString * imgStr = cell.textLabel.text; 850#ifdef __GENIE_IPHONE__ 851 UIImage * img = image;//[UIImage imageNamed:lanDeviceInfo.icon]; 852 UIImage * icon = nil; 853 UIGraphicsBeginImageContext(CGSizeMake(37.0f, 37.0f)); 854 CGRect rec = CGRectMake(0, 0, 37.0f, 37.0f); 855 [img drawInRect:rec]; 856 icon = UIGraphicsGetImageFromCurrentImageContext(); 857 UIGraphicsEndImageContext(); 858 cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold"size:14];//[UIFont boldSystemFontOfSize:14]; 859 cell.imageView.image = icon; 860#else 861 cell.imageView.image = image; 862#endif 863 864 return cell; 865 866} 867 868- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { 869 870 if ([[[BonjourServiceResolving GetBonjourResolvInstance] getIPArray] count] == 0) 871 return nil; 872 873 return indexPath; 874} 875 876- (void)stopCurrentResolve { 877 878 self.needsActivityIndicator = NO; 879 self.timer = nil; 880 881 [self.currentResolve stop]; 882 //[self.currentResolve release]; //add by hi.tan for mem leak 883 self.currentResolve = nil; 884} 885 886- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 887 888 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 889 //hi.tan:文件拾取器 890 UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:Localization_FileTransfer_Select_Send_File_Type delegate:self cancelButtonTitle:Localization_Cancel destructiveButtonTitle:Localization_FileTransfer_File_Photo otherButtonTitles:Localization_FileTransfer_File_Video,Localization_FileTransfer_File_History, nil];//Localization_FileTransfer_File_Text 891 actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic; 892 //CGRect rect = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + self.view.frame.size.height/2, self.view.frame.size.width, self.view.frame.size.height/2); 893 [actionSheet showInView:self.view]; 894 //[actionSheet showFromRect:rect inView:self.view animated:NO]; 895 //[actionSheet showFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:NO]; 896 [actionSheet release]; 897 898 NSMutableArray *IParray = [NSMutableArray arrayWithArray:[[BonjourServiceResolving GetBonjourResolvInstance] getIPArray]]; 899 900 NSMutableDictionary *dic = nil; 901 if(indexPath.row < [IParray count]) 902 { 903 dic = [IParray objectAtIndex:indexPath.row]; 904 [PlistManipulate setDeviceMess:dic]; 905 } 906 [pool release]; 907} 908 909- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ 910 switch (buttonIndex) { 911 case 0://照片:可以选多张8af249912#ifdef UserBehaviourZ913 [GenieAdvanceInfoStatistics GetInstance].turboTransfer.TT4++; 914#endif291400915 [self pickMultiplePhotos];Z916 break; 917 case 1://视频:只能一次选择一个8af249918#ifdef UserBehaviourZ919 [GenieAdvanceInfoStatistics GetInstance].turboTransfer.TT3++; 920#endif291400921 [self pickSingleVideoFile];Z922 break; 923// case 2://剪切板 924// [self openMessage]; 925 break; 926 case 2://3://历史文件 927 [self openHistory]; 928 break; 929 default: 930 //取消 931 break; 932 } 933} 934//跳转到剪切板 935-(IBAction)openMessage{ 936 TextMessageViewController *messageView = [[TextMessageViewController alloc] init]; 937 //MessageViewController *messageView = [[MessageViewController alloc] init]; 938 //NSDictionary *dic = [PlistManipulate getDeviceMessage]; 939 //messageView.deviceDic = dic; 940 [self.navigationController pushViewController:messageView animated:YES]; 941 [messageView release]; 942} 943 944 945//跳转到历史纪录页面 946-(IBAction)openHistory{ 947 HistoryViewController *history = [[HistoryViewController alloc]init]; 948 history.isToSelectFileForTransfer = YES; 949 history.delegate = self; 950 //[self.navigationController pushViewController:history animated:YES]; 951 //hi.tan: 在IOS8上的特殊处理 952 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 953 { 954#ifdef __GENIE_IPHONE__ 955 [self.navigationController pushViewController:history animated:YES]; 956#else 957 dispatch_async(dispatch_get_main_queue(), ^{ 958 [self.navigationController pushViewController:history animated:YES]; 959 }); 960#endif 961 } 962 else 963 { 964 [self.navigationController pushViewController:history animated:YES]; 965 } 966 //hi.tan: 在IOS8上的特殊处理 967 [history release]; 968} 969 970#pragma mark - HistoryViewControllerdelegate 971- (void)tellTheTransferFileName:(NSString *)fileName andFilePath:(NSString *)filePath{ 972 //_myFileTransfer = [[FileTransferViewController alloc] init]; 973 // add by hi.tan: 974 [FileTransferViewController ReleaseInstance]; 975 FileTransferViewController *viewController = [FileTransferViewController SharedFileTransfer]; 976 NSDictionary *dic = [PlistManipulate getDeviceMessage]; 977 NSString *name = [[UIDevice currentDevice] name]; 978 viewController.sendIp = [NSString stringWithString:[dic objectForKey:@"ipAddr"]]; 979 viewController.sendDeviceName = name; 980 viewController.receiveDeviceName = [NSString stringWithString:[dic objectForKey:@"serviceName"]]; 981 //设置为1 为发送标记 982 viewController.fileFlag = [NSString stringWithFormat:@"1"]; 983 //发送文件 984 985 [viewController.imageUrls removeAllObjects]; 986 //[viewController.imageUrls addObject:filePath]; 987 NSData *data = [NSData dataWithContentsOfFile:filePath]; 988 NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 989 NSString * documentsDirectory = [paths objectAtIndex:0]; 990 NSString * sendingFileDir = [documentsDirectory stringByAppendingPathComponent:@"Sent"]; 991 992 NSFileManager *fileManager = [NSFileManager defaultManager]; 993 BOOL isDir = FALSE; 994 BOOL isDirExist = [fileManager fileExistsAtPath:sendingFileDir isDirectory:&isDir]; 995 if(!(isDirExist && isDir)) 996 { 997 BOOL bCreateDir = [fileManager createDirectoryAtPath:sendingFileDir withIntermediateDirectories:YES attributes:nil error:nil]; 998 if(!bCreateDir){ 999 NSLog(@"Create Audio Directory Failed."); 1000 return; 1001 } 1002 NSLog(@"%@",sendingFileDir); 1003 1004 NSString * sendingFilePath = [sendingFileDir stringByAppendingPathComponent:fileName]; 1005 [data writeToFile:sendingFilePath atomically:YES]; 1006 [viewController.imageUrls addObject:sendingFilePath]; 1007 } 1008 else 1009 { 1010 NSString *sendingFilePath = [sendingFileDir stringByAppendingPathComponent:fileName]; 1011 [data writeToFile:sendingFilePath atomically:YES]; 1012 [viewController.imageUrls addObject:sendingFilePath]; 1013 } 1014 1015 [self.navigationController pushViewController:viewController animated:YES]; 1016} 1017 1018 1019// add by hi.tan for :多个图片文件拾取器 1020#pragma mark multi photos picker controller and delegation 1021- (IBAction)pickSinglePhoto 1022{ 1023// QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init]; 1024// imagePickerController.delegate = self; 1025// 1026// UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePickerController]; 1027// [self presentViewController:navigationController animated:YES completion:NULL]; 1028// [imagePickerController release]; 1029// [navigationController release]; 1030} 1031 1032- (IBAction)pickMultiplePhotos 1033{ 1034 QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init]; 1035 // add by hi.tan : 照片和视频文件类型选取分开 1036 NSInteger index = 0; 1037 1038 if(index == 0){ // 照片 1039 imagePickerController.filterType = QBImagePickerFilterTypeAllPhotos; 1040 imagePickerController.title = @"Photos"; 1041 } 1042 else if(index == 1){ //视频 1043 1044 imagePickerController.filterType = QBImagePickerFilterTypeAllVideos; 1045 imagePickerController.title = @"Videos"; 1046 } 1047 1048 imagePickerController.delegate = self; 1049 imagePickerController.allowsMultipleSelection = YES; 1050 1051 imagePickerController.limitsMaximumNumberOfSelection = YES; 1052 imagePickerController.maximumNumberOfSelection = 10; // 添加一次选中图片最多张数限制为10 1053 1054 UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePickerController]; 1055 //[self presentViewController:navigationController animated:YES completion:NULL]; 1056 //hi.tan: 在IOS8上的特殊处理 1057 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 1058 { 1059 dispatch_async(dispatch_get_main_queue(), ^{ 1060 [self presentViewController:navigationController animated:YES completion:nil]; 1061 }); 1062 } 1063 else 1064 { 1065 [self presentViewController:navigationController animated:YES completion:nil]; 1066 } 1067 1068 [imagePickerController release]; 1069 [navigationController release]; 1070} 1071 1072 1073- (IBAction)pickWithLimitation 1074{ 1075// QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init]; 1076// imagePickerController.delegate = self; 1077// imagePickerController.allowsMultipleSelection = YES; 1078// 1079// imagePickerController.limitsMinimumNumberOfSelection = YES; 1080// imagePickerController.minimumNumberOfSelection = 6; 1081// 1082// UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePickerController]; 1083// [self presentViewController:navigationController animated:YES completion:NULL]; 1084// [imagePickerController release]; 1085// [navigationController release]; 1086} 1087 1088 1089-(IBAction)pickSingleVideoFile 1090{ 1091 UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 1092 imagePicker.delegate = self; 1093 imagePicker.allowsEditing = YES; 1094 1095//#ifdef __GENIE_IPHONE__ 1096// imagePicker.sourceType =UIImagePickerControllerSourceTypeSavedPhotosAlbum;// UIImagePickerControllerSourceTypePhotoLibrary; 1097// //hi.tan: 修改为只显示视频类型的文件供用户选择 1098// imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil]; 1099// 1100// [self presentModalViewController:imagePicker animated:YES]; 1101//// UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePicker]; 1102//// [self presentViewController:navigationController animated:YES completion:NULL]; 1103// [imagePicker release]; 1104// //[navigationController release]; 1105// 1106//#else 1107// imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;//UIImagePickerControllerSourceTypePhotoLibrary; 1108// imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil]; 1109// 1110// popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 1111// [popoverController presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 1112// [imagePicker release]; 1113//#endif 1114 1115#ifdef __GENIE_IPHONE__ 1116 imagePicker.sourceType =UIImagePickerControllerSourceTypeSavedPhotosAlbum;// UIImagePickerControllerSourceTypePhotoLibrary; 1117 //hi.tan: 修改为只显示视频类型的文件供用户选择 1118 imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil]; 1119 1120 [self presentModalViewController:imagePicker animated:YES]; 1121 [imagePicker release]; 1122 1123#else 1124 imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;//UIImagePickerControllerSourceTypePhotoLibrary; 1125 imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil]; 1126 popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 1127 //hi.tan: 在IOS8上的特殊处理 1128 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 1129 { 1130 dispatch_async(dispatch_get_main_queue(), ^{ 1131 [popoverController presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 1132 }); 1133 } 1134 else 1135 { 1136 [popoverController presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 1137 } 1138 //hi.tan: 在IOS8上的特殊处理 1139 [imagePicker release]; 1140#endif 1141} 1142 1143#pragma mark - 1144#pragma UIImagePickerController Delegate 1145//- (void)imagePickerController:(id)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 1146- (void)imagePickerController:(UIViewController *)picker didFinishPickingMediaWithInfo:(id)info 1147{ 1148 1149 UIViewController *pickView = picker; 1150 FileTransferViewController *viewController = [FileTransferViewController SharedFileTransfer]; 1151 1152 if([pickView isKindOfClass:[QBImagePickerController class]]) //说明是图片选择器 1153 { 1154 1155 //创建发送文件目录,并将图片移动到改目录 1156 NSString *date; 1157 NSMutableString *dateTmp; 1158 NSDateFormatter* formatter = [[NSDateFormatter alloc]init]; 1159 //hi.tan edited:修改传输文件的名称 1160 //[formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"]; 1161 [formatter setDateFormat:@"YYYYMMddhhmmss"]; 1162 date = [formatter stringFromDate:[NSDate date]]; 1163 1164 //hi.tan: 文件名称在iphone iOS8上后,date带有:号,统一都给去掉 1165 dateTmp = [[NSMutableString alloc] initWithString:date]; 1166 1167 NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:@":" 1168 options:NSRegularExpressionCaseInsensitive 1169 error:nil]; 1170 1171 [regex replaceMatchesInString:dateTmp options:0 range:NSMakeRange(0, [dateTmp length]) withTemplate:@""]; 1172 date = [NSString stringWithString:dateTmp]; 1173 [dateTmp release]; 1174 [regex release]; 1175 1176 [formatter release]; //hi.tan for mem leak 1177 1178 int totalPicked = [info count]; 1179 int i = 0; 1180 1181 [viewController.imageUrls removeAllObjects]; 1182 1183 for(i = 0; i<totalPicked;i++) 1184 { 1185 NSString *mediaType = [info[i] objectForKey:UIImagePickerControllerMediaType]; //ALAssetTypePhoto ALAssetTypeVideo 1186 1187 if ([mediaType isEqualToString:@"ALAssetTypePhoto"]) 1188 { 1189 // UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 1190 UIImage *image = [info[i] objectForKey:@"UIImagePickerControllerOriginalImage"]; 1191 NSLog(@"found an image"); 1192 1193 NSURL *imageFormate = [info[i] objectForKey:@"UIImagePickerControllerReferenceURL"]; 1194 1195 NSString *imageName = nil; 1196 1197 if([[imageFormate absoluteString] hasSuffix:@"JPG"] || [[imageFormate absoluteString] hasSuffix:@"jpg"]){ 1198 //NSLog(@"imageFormate = JPG"); 1199 imageName = [NSString stringWithFormat:@"%@%d.JPG",date,i]; 1200 } 1201 else if([[imageFormate absoluteString] hasSuffix:@"PNG"] || [[imageFormate absoluteString] hasSuffix:@"png"]){ 1202 //NSLog(@"imageFormate = PNG"); 1203 imageName = [NSString stringWithFormat:@"%@%d.PNG",date,i]; 1204 } 1205 else if([[imageFormate absoluteString] hasSuffix:@"GIF"] || [[imageFormate absoluteString] hasSuffix:@"gif"]){ 1206 //NSLog(@"imageFormate = GIF"); 1207 imageName = [NSString stringWithFormat:@"%@%d.GIF",date,i]; 1208 } 1209 else if([[imageFormate absoluteString] hasSuffix:@"BMP"] || [[imageFormate absoluteString] hasSuffix:@"bmp"]){ 1210 //NSLog(@"imageFormate = BMP"); 1211 imageName = [NSString stringWithFormat:@"%@%d.BMP",date,i]; 1212 } 1213 else if([[imageFormate absoluteString] hasSuffix:@"TIF"] || [[imageFormate absoluteString] hasSuffix:@"tif"]){ 1214 //NSLog(@"imageFormate = BMP"); 1215 imageName = [NSString stringWithFormat:@"%@%d.TIF",date,i]; 1216 } 1217 [viewController saveImage:image WithName:imageName]; 1218 } 1219 } 1220 1221 } 1222 else if([pickView isKindOfClass:[UIImagePickerController class]])//说明是用了视频拾取器 1223 { 1224 NSLog(@"info = %@",info); 1225 1226 if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeMovie]) 1227 { 1228 NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; 1229 NSData *fileData = [NSData dataWithContentsOfFile:videoPath]; 1230 NSLog(@"The video file length = %d", [fileData length]); 1231 1232 NSArray *pathArray = [videoPath componentsSeparatedByString:@"//"]; 1233 NSString *tmpFileName = pathArray[[pathArray count] -1]; 1234 NSArray *fileNameArray = [tmpFileName componentsSeparatedByString:@"."]; 1235 NSString *videoFileName = [[fileNameArray[1] stringByAppendingString:@"."] stringByAppendingString:fileNameArray[[fileNameArray count] - 1]]; 1236 1237 NSFileManager *fileManager = [NSFileManager defaultManager]; 1238 1239 NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 1240 NSString * documentsDirectory = [paths objectAtIndex:0]; 1241 NSString * fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"Sent"]; 1242 1243 BOOL isDir = FALSE; 1244 BOOL isDirExist = [fileManager fileExistsAtPath:fullPathToFile isDirectory:&isDir]; 1245 if(!(isDirExist && isDir)) 1246 { 1247 BOOL bCreateDir = [fileManager createDirectoryAtPath:fullPathToFile withIntermediateDirectories:YES attributes:nil error:nil]; 1248 if(!bCreateDir){ 1249 NSLog(@"Create Audio Directory Failed."); 1250 return; 1251 } 1252 NSLog(@"%@",fullPathToFile); 1253 1254 NSString *videoFilePath = [fullPathToFile stringByAppendingPathComponent:videoFileName]; 1255 [fileData writeToFile:videoFilePath atomically:YES]; 1256 [viewController.imageUrls addObject:videoFilePath]; 1257 }else{ 1258 NSString *videoFilePath = [fullPathToFile stringByAppendingPathComponent:videoFileName]; 1259 [fileData writeToFile:videoFilePath atomically:YES]; 1260 [viewController.imageUrls addObject:videoFilePath]; 1261 } 1262 } 1263#if !defined (__GENIE_IPHONE__) 1264 if(popoverController != nil) 1265 { 1266 [popoverController dismissPopoverAnimated:YES]; 1267 } 1268#endif 1269 } 1270 1271 [picker dismissModalViewControllerAnimated:YES]; 1272 1273// if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeImage]) 1274// { 1275// UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage]; 1276// NSData *fileData = UIImageJPEGRepresentation(img, 1.0); 1277// } 1278// else if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeMovie]) 1279// { 1280// NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; 1281// NSData *fileData = [NSData dataWithContentsOfFile:videoPath]; 1282// NSLog(@"The video file length = %d", [fileData length]); 1283// } 1284 1285 NSDictionary *dic = [PlistManipulate getDeviceMessage]; 1286 NSString *name = [[UIDevice currentDevice] name]; 1287 NSString *ip = [NSString stringWithString:[dic objectForKey:@"ipAddr"]]; 1288 NSLog(@"The dest ip to send file address = %@",ip); 1289 viewController.sendDeviceName = name; 1290 viewController.receiveDeviceName = [NSString stringWithString:[dic objectForKey:@"serviceName"]]; 1291 viewController.sendIp = ip; 1292 //设置为1 为发送标记 1293 viewController.fileFlag = [NSString stringWithFormat:@"1"]; 1294 //发送文件 1295 [self.navigationController pushViewController:viewController animated:YES]; 1296 //hi.tan 1297 1298} 1299 1300- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 1301{ 1302 [picker dismissModalViewControllerAnimated:YES]; 1303} 1304/* 1305#pragma mark - QBImagePickerControllerDelegate 1306// add by hi.tan: 多个图片文件拾取器 1307- (void)imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingMediaWithInfo:(id)info 1308{ 1309 NSLog(@"info:%@",info); 1310 // hi.tan 1311 1312 [imagePickerController dismissModalViewControllerAnimated:YES]; 1313 // _myFileTransfer = [[FileTransferViewController alloc] init]; 1314 //add by hi.tan 1315 FileTransferViewController *viewController = [FileTransferViewController SharedFileTransfer]; 1316 //截取文件名 1317 // self.imageName = @"11111";//[self setPhotoName:imageButton.imageURL]; 1318 //创建发送文件目录,并将图片移动到改目录 1319 NSString* date; 1320 NSDateFormatter* formatter = [[NSDateFormatter alloc]init]; 1321 //hi.tan edited:修改传输文件的名称 1322 //[formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"]; 1323 [formatter setDateFormat:@"YYYYMMddhhmmss"]; 1324 date = [formatter stringFromDate:[NSDate date]]; 1325 [formatter release]; //hi.tan for mem leak 1326 1327 int totalPicked = [info count]; 1328 int i = 0; 1329 1330 [viewController.imageUrls removeAllObjects]; 1331 1332 for(i = 0; i<totalPicked;i++) 1333 { 1334 NSString *mediaType = [info[i] objectForKey:UIImagePickerControllerMediaType]; //ALAssetTypePhoto ALAssetTypeVideo 1335 1336 if ([mediaType isEqualToString:@"ALAssetTypePhoto"]){ 1337 // UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 1338 UIImage *image = [info[i] objectForKey:@"UIImagePickerControllerOriginalImage"]; 1339 NSLog(@"found an image"); 1340 1341 NSURL *imageFormate = [info[i] objectForKey:@"UIImagePickerControllerReferenceURL"]; 1342 1343 NSData *webData = [NSData dataWithContentsOfURL:imageFormate]; 1344 1345 NSString *imageName = nil; 1346 1347 if([[imageFormate absoluteString] hasSuffix:@"JPG"] || [[imageFormate absoluteString] hasSuffix:@"jpg"]){ 1348 //NSLog(@"imageFormate = JPG"); 1349 imageName = [NSString stringWithFormat:@"Image%@%d.JPG",date,i]; 1350 } 1351 else if([[imageFormate absoluteString] hasSuffix:@"PNG"] || [[imageFormate absoluteString] hasSuffix:@"png"]){ 1352 //NSLog(@"imageFormate = PNG"); 1353 imageName = [NSString stringWithFormat:@"Image%@%d.PNG",date,i]; 1354 } 1355 else if([[imageFormate absoluteString] hasSuffix:@"GIF"] || [[imageFormate absoluteString] hasSuffix:@"gif"]){ 1356 //NSLog(@"imageFormate = GIF"); 1357 imageName = [NSString stringWithFormat:@"Image%@%d.GIF",date,i]; 1358 } 1359 else if([[imageFormate absoluteString] hasSuffix:@"BMP"] || [[imageFormate absoluteString] hasSuffix:@"bmp"]){ 1360 //NSLog(@"imageFormate = BMP"); 1361 imageName = [NSString stringWithFormat:@"Image%@%d.BMP",date,i]; 1362 } 1363 else if([[imageFormate absoluteString] hasSuffix:@"TIF"] || [[imageFormate absoluteString] hasSuffix:@"tif"]){ 1364 //NSLog(@"imageFormate = BMP"); 1365 imageName = [NSString stringWithFormat:@"Image%@%d.TIF",date,i]; 1366 } 1367 [viewController saveImage:image WithName:imageName]; 1368 //[UIImageJPEGRepresentation(image, 1.0f) writeToFile:[self findUniqueSavePath] atomically:YES]; 1369 //SETIMAGE(image); 1370 //CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]); 1371 } 1372 else if ([mediaType isEqualToString:@"ALAssetTypeVideo"]){ 1373 1374 ALAssetsLibrary *lib; 1375 1376 AVAssetReaderAudioMixOutput *out; 1377 1378 //NSURL *videoURL = [info[i] objectForKey:UIImagePickerControllerMediaURL]; 1379 NSURL *videoURL = [info[i] objectForKey:UIImagePickerControllerMediaURL]; 1380 1381 NSInputStream *input = [NSInputStream inputStreamWithURL:videoURL]; 1382 1383 //AVURLAsset *asset = [[AVURLAsset alloc] initWithURL: videoURL options:nil]; 1384 1385 //NSString* path = [videoURL path]; 1386 //UISaveVideoAtPathToSavedPhotosAlbum(path,self, @selector(video:didFinishSavingWithError:contextInfo:),nil); 1387 NSLog(@"found a video: videoURL = %@",videoURL); 1388 NSData *webData = [NSData dataWithContentsOfURL:videoURL]; 1389 //NSData *webData = [NSData dataWithContentsOfFile:path]; 1390 1391 NSString *vedioName = nil; 1392 if([[videoURL absoluteString] hasSuffix:@"MOV"] || [[videoURL absoluteString] hasSuffix:@"mov"]){ // 扩展对视频文件格式的支持 1393 //NSLog(@"imageFormate = BMP"); 1394 vedioName = [NSString stringWithFormat:@"%@%d.MOV",date,i]; 1395 } 1396 else if([[videoURL absoluteString] hasSuffix:@"MP4"] || [[videoURL absoluteString] hasSuffix:@"mp4"]){ // 扩展对视频文件格式的支持 1397 //NSLog(@"imageFormate = BMP"); 1398 vedioName = [NSString stringWithFormat:@"%@%d.MP4",date,i]; 1399 } 1400 else if([[videoURL absoluteString] hasSuffix:@"AVI"] || [[videoURL absoluteString] hasSuffix:@"avi"]){ // 扩展对视频文件格式的支持 1401 //NSLog(@"imageFormate = BMP"); 1402 vedioName = [NSString stringWithFormat:@"%@%d.AVI",date,i]; 1403 } 1404 else if([[videoURL absoluteString] hasSuffix:@"3GP"] || [[videoURL absoluteString] hasSuffix:@"3gp"]){ // 扩展对视频文件格式的支持 1405 //NSLog(@"imageFormate = BMP"); 1406 vedioName = [NSString stringWithFormat:@"%@%d.3GP",date,i]; 1407 } 1408 else if([[videoURL absoluteString] hasSuffix:@"AVC"] || [[videoURL absoluteString] hasSuffix:@"avc"]){ // 扩展对视频文件格式的支持 1409 //NSLog(@"imageFormate = BMP"); 1410 vedioName = [NSString stringWithFormat:@"%@%d.AVC",date,i]; 1411 } 1412 else if([[videoURL absoluteString] hasSuffix:@"MPEG"] || [[videoURL absoluteString] hasSuffix:@"mpeg"]){ // 扩展对视频文件格式的支持 1413 //NSLog(@"imageFormate = BMP"); 1414 vedioName = [NSString stringWithFormat:@"%@%d.MPEG",date,i]; 1415 } 1416 else if([[videoURL absoluteString] hasSuffix:@"FLV"] || [[videoURL absoluteString] hasSuffix:@"flv"]){ // 扩展对视频文件格式的支持 1417 //NSLog(@"imageFormate = BMP"); 1418 vedioName = [NSString stringWithFormat:@"%@%d.FLV",date,i]; 1419 } 1420 else if([[videoURL absoluteString] hasSuffix:@"IPOD"] || [[videoURL absoluteString] hasSuffix:@"ipod"]){ // 扩展对视频文件格式的支持 1421 //NSLog(@"imageFormate = BMP"); 1422 vedioName = [NSString stringWithFormat:@"%@%d.IPOD",date,i]; 1423 } 1424 else if([[videoURL absoluteString] hasSuffix:@"PSP"] || [[videoURL absoluteString] hasSuffix:@"psp"]){ // 扩展对视频文件格式的支持 1425 //NSLog(@"imageFormate = BMP"); 1426 vedioName = [NSString stringWithFormat:@"%@%d.PSP",date,i]; 1427 } 1428 else if([[videoURL absoluteString] hasSuffix:@"SWF"] || [[videoURL absoluteString] hasSuffix:@"swf"]){ // 扩展对视频文件格式的支持 1429 //NSLog(@"imageFormate = BMP"); 1430 vedioName = [NSString stringWithFormat:@"%@%d.SWF",date,i]; 1431 } 1432 else if([[videoURL absoluteString] hasSuffix:@"WMV"] || [[videoURL absoluteString] hasSuffix:@"wmv"]){ // 扩展对视频文件格式的支持 1433 //NSLog(@"imageFormate = BMP"); 1434 vedioName = [NSString stringWithFormat:@"%@%d.WMV",date,i]; 1435 } 1436 else if([[videoURL absoluteString] hasSuffix:@"MJPEG"] || [[videoURL absoluteString] hasSuffix:@"mjpeg"]){ // 扩展对视频文件格式的支持 1437 //NSLog(@"imageFormate = BMP"); 1438 vedioName = [NSString stringWithFormat:@"%@%d.MJPEG",date,i]; 1439 } 1440 else if([[videoURL absoluteString] hasSuffix:@"WMA"] || [[videoURL absoluteString] hasSuffix:@"wma"]){ // 扩展对视频文件格式的支持 1441 //NSLog(@"imageFormate = BMP"); 1442 vedioName = [NSString stringWithFormat:@"%@%d.WMA",date,i]; 1443 } 1444 else if([[videoURL absoluteString] hasSuffix:@"RM"] || [[videoURL absoluteString] hasSuffix:@"rm"]){ // 扩展对视频文件格式的支持 1445 //NSLog(@"imageFormate = BMP"); 1446 vedioName = [NSString stringWithFormat:@"%@%d.RM",date,i]; 1447 } 1448 else if([[videoURL absoluteString] hasSuffix:@"FLAC"] || [[videoURL absoluteString] hasSuffix:@"flac"]){ // 扩展对视频文件格式的支持 1449 //NSLog(@"imageFormate = BMP"); 1450 vedioName = [NSString stringWithFormat:@"%@%d.FLAC",date,i]; 1451 } 1452 else if([[videoURL absoluteString] hasSuffix:@"WAV"] || [[videoURL absoluteString] hasSuffix:@"wav"]){ // 扩展对视频文件格式的支持 1453 //NSLog(@"imageFormate = BMP"); 1454 vedioName = [NSString stringWithFormat:@"%@%d.WAV",date,i]; 1455 } 1456 1457 NSFileManager *fileManager = [NSFileManager defaultManager]; 1458 NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 1459 NSString * documentsDirectory = [paths objectAtIndex:0]; 1460 NSString * fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"Sent"]; 1461 1462 BOOL isDir = FALSE; 1463 BOOL isDirExist = [fileManager fileExistsAtPath:fullPathToFile isDirectory:&isDir]; 1464 if(!(isDirExist && isDir)) 1465 { 1466 BOOL bCreateDir = [fileManager createDirectoryAtPath:fullPathToFile withIntermediateDirectories:YES attributes:nil error:nil]; 1467 if(!bCreateDir) 1468 { 1469 NSLog(@"Create Audio Directory Failed."); 1470 return; 1471 } 1472 //NSLog(@"%@",fullPathToFile); 1473 NSString *videoFullPath = [fullPathToFile stringByAppendingPathComponent:vedioName]; 1474 //[webData writeToFile:videoFullPath atomically:YES]; 1475 UISaveVideoAtPathToSavedPhotosAlbum(videoFullPath,self, nil,nil); 1476 [viewController.imageUrls addObject:videoFullPath]; 1477 }else 1478 { 1479 NSString *videoFullPath = [fullPathToFile stringByAppendingPathComponent:vedioName]; 1480 //[webData writeToFile:videoFullPath atomically:YES]; 1481 UISaveVideoAtPathToSavedPhotosAlbum(videoFullPath,self, nil,nil); 1482 [viewController.imageUrls addObject:videoFullPath]; 1483 } 1484 1485 //[webData writeToFile:[self findUniqueMoviePath] atomically:YES]; 1486 //CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]); 1487 // NSLog(videoURL); 1488 } 1489 //[picker dismissModalViewControllerAnimated:YES]; 1490 } 1491 1492 //mov mp4 avi 3gp avc mpeg flv ipod psp swf wmv mjpeg wma rm flac wav mp3 1493 1494 NSDictionary *dic = [PlistManipulate getDeviceMessage]; 1495 NSString *name = [[UIDevice currentDevice] name]; 1496 NSString *ip = [NSString stringWithString:[dic objectForKey:@"ipAddr"]]; 1497 NSLog(@"The dest ip to send file address = %@",ip); 1498 viewController.sendDeviceName = name; 1499 viewController.receiveDeviceName = [NSString stringWithString:[dic objectForKey:@"serviceName"]]; 1500 viewController.sendIp = ip; 1501 //设置为1 为发送标记 1502 viewController.fileFlag = [NSString stringWithFormat:@"1"]; 1503 //发送文件 1504 [self.navigationController pushViewController:viewController animated:YES]; 1505 //hi.tan 1506} 1507 1508- (void)imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController 1509{ 1510 NSLog(@"Cancelled"); 1511 1512 [self dismissViewControllerAnimated:YES completion:NULL]; 1513} 1514 1515//hi.tan : 更新选择所有文件提示信息(图片和视频分开提示) 1516 1517- (NSString *)descriptionForSelectingAllAssets:(QBImagePickerController *)imagePickerController 1518{ 1519 NSString *str; 1520 if(imagePickerController.filterType == QBImagePickerFilterTypeAllPhotos){ 1521 str= Localization_FileTransfer_Select_All_Photos; 1522 } 1523 else{ 1524 str= Localization_FileTransfer_Select_All_Videos; 1525 } 1526 return str; 1527 //return @"选择所有照片"; 1528} 1529 1530- (NSString *)descriptionForDeselectingAllAssets:(QBImagePickerController *)imagePickerController 1531{ 1532 NSString *str; 1533 if(imagePickerController.filterType == QBImagePickerFilterTypeAllPhotos){ 1534 str = Localization_FileTransfer_Deselect_All_Photos; 1535 } 1536 else{ 1537 str = Localization_FileTransfer_Deselect_All_Videos; 1538 } 1539 return str; 1540 //return @"取消所有照片"; 1541} 1542 1543 1544- (NSString *)imagePickerController:(QBImagePickerController *)imagePickerController descriptionForNumberOfPhotos:(NSUInteger)numberOfPhotos 1545{ 1546 //return [NSString stringWithFormat:@"相片%d张", numberOfPhotos]; 1547 NSString *tmp = Localization_FileTransfer_All_Photos_Counter; 1548 NSString * str = [tmp stringByAppendingFormat:@": %d", numberOfPhotos]; 1549 return str; 1550 //return [str autorelease]; 1551} 1552 1553- (NSString *)imagePickerController:(QBImagePickerController *)imagePickerController descriptionForNumberOfVideos:(NSUInteger)numberOfVideos 1554{ 1555 //return [NSString stringWithFormat:@"视频%d集", numberOfVideos]; 1556 NSString *tmp = Localization_FileTransfer_All_Video_Counter; 1557 NSString * str = [tmp stringByAppendingFormat:@": %d", numberOfVideos]; 1558 return str; 1559 //return [str autorelease]; 1560} 1561 1562- (NSString *)imagePickerController:(QBImagePickerController *)imagePickerController descriptionForNumberOfPhotos:(NSUInteger)numberOfPhotos numberOfVideos:(NSUInteger)numberOfVideos 1563{ 1564 NSString *tmp1 = Localization_FileTransfer_All_Photos_Counter; 1565 NSString * str1 = [tmp1 stringByAppendingFormat:@": %d ", numberOfPhotos]; 1566 NSString * str2 = [str1 stringByAppendingFormat:Localization_FileTransfer_All_Photos_Counter]; 1567 NSString *str3 = [str2 stringByAppendingFormat:@": %d", numberOfVideos]; 1568 return str3; 1569 //return [NSString stringWithFormat:@"照片%d张、视频%d集", numberOfPhotos, numberOfVideos]; 1570} 1571// add by hi.tan: 多个图片文件拾取器 1572*/ 1573 1574 1575// If necessary, sets up state to show an activity indicator to let the user know that a resolve is occuring. 1576- (void)showWaiting:(NSTimer *)timer { 1577 if (timer == self.timer) { 1578 NSNetService* service = (NSNetService*)[self.timer userInfo]; 1579 if (self.currentResolve == service) { 1580 self.needsActivityIndicator = YES; 1581 1582 NSIndexPath* indexPath = [NSIndexPath indexPathForRow:[self.services indexOfObject:self.currentResolve] inSection:0]; 1583 if (indexPath.row != NSNotFound) { 1584 [m_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 1585 // Deselect the row since the activity indicator shows the user something is happening. 1586 [m_tableView deselectRowAtIndexPath:indexPath animated:YES]; 1587 } 1588 } 1589 } 1590} 1591 1592- (void)initialWaitOver:(NSTimer *)timer { 1593 self.initialWaitOver= YES; 1594 if (![self.services count]) 1595 [m_tableView reloadData]; 1596} 1597 1598- (void)sortAndUpdateUI { 1599 // Sort the services by name. 1600 [self.services sortUsingSelector:@selector(localizedCaseInsensitiveCompareByName:)]; 1601 [m_tableView reloadData]; 1602} 1603 1604 1605 1606/* 1607- (void)netServiceBrowser:(NSNetServiceBrowser *)netServiceBrowser didRemoveService:(NSNetService *)service moreComing:(BOOL)moreComing { 1608 1609 if (self.currentResolve && [service isEqual:self.currentResolve]) { 1610 [self stopCurrentResolve]; 1611 } 1612 1613 1614 [self.services removeObject:service]; 1615 1616 if (self.ownEntry == service) 1617 self.ownEntry = nil; 1618 if (!moreComing) { 1619 [self sortAndUpdateUI]; 1620 } 1621 1622 [[NSNotificationCenter defaultCenter] postNotificationName:@"BonjourChange" object:nil userInfo:nil]; 1623} 1624 1625- (void)netServiceBrowser:(NSNetServiceBrowser *)netServiceBrowser didFindService:(NSNetService *)service moreComing:(BOOL)moreComing { 1626 1627 // If a service came online, add it to the list and update the table view if no more events are queued. 1628 //hi.tan:设备名称作为服务名称的处理 1629 NSString *selfName = nil;//[[UIDevice currentDevice] name]; 1630 NSString *tmpname = [[[UIDevice currentDevice] name] stringByReplacingOccurrencesOfString:@"." withString:@"_"]; 1631 if([tmpname hasPrefix:@"_"]){ 1632 selfName = [tmpname substringFromIndex:1]; 1633 } 1634 else{ 1635 selfName = tmpname; 1636 } 1637 // end by hi.tan 1638 1639 NSString *servName = service.name; 1640 1641 NSLog(@"\nThe new income service = %@",servName); 1642 1643 if ([servName isEqual:selfName] || [servName hasPrefix:selfName]) //此处判断有待改进 1644 //if ([service.name isEqual:self.ownName]) 1645 self.ownEntry = service; 1646 else{ 1647 1648 if (![self.services containsObject:service] ) { 1649 // Add it to our list 1650 [self.services addObject:service]; 1651 } 1652// [self.services addObject:service]; 1653 1654 self.currentResolve = service; 1655 [self.currentResolve setDelegate:self]; 1656 1657 [self.currentResolve resolveWithTimeout:100]; 1658 1659 self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showWaiting:) userInfo:self.currentResolve repeats:NO]; 1660 1661 } 1662 1663 if (!moreComing) { 1664 [self sortAndUpdateUI]; 1665 } 1666 1667 [[NSNotificationCenter defaultCenter] postNotificationName:@"BonjourChange" object:nil userInfo:nil]; 1668} 1669 1670- (void)netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict { 1671 [self stopCurrentResolve]; 1672 [m_tableView reloadData]; 1673} 1674 1675//解析ip地址 1676-(NSMutableDictionary *) getIpAddr:(NSNetService *)service{ 1677 1678 NSString *name = nil; 1679 NSData *address = nil; 1680 struct sockaddr_in *socketAddress = nil; 1681 NSString *ipString = nil; 1682 int port; 1683 uint i; 1684 for (i = 0; i < [[service addresses] count]; i++) 1685 { 1686 name = [service name]; 1687 address = [[service addresses] objectAtIndex:i]; 1688 socketAddress = (struct sockaddr_in *) 1689 [address bytes]; 1690 if (![[NSString stringWithFormat: @"%s", 1691 inet_ntoa (socketAddress->sin_addr)] isEqual:@"0.0.0.0"]) { 1692 ipString = [NSString stringWithFormat: @"%s", 1693 inet_ntoa(socketAddress->sin_addr)]; 1694 } 1695 1696 port = socketAddress->sin_port; 1697 NSLog(@"Server found is %@ %d",ipString,port); 1698 } 1699 if(ipString == Nil) 1700 { 1701 //ipString = @"0.0.0.0"; 1702 if ([self.services containsObject:service]) 1703 { 1704 [self.services removeObject:service]; 1705 } 1706 return nil; 1707 } 1708 1709 NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:10]; //hi.tan : mem leak 1710 [dic setObject:[NSString stringWithFormat:@"%d",port] forKey:@"port"]; 1711 [dic setObject:ipString forKey:@"ipAddr"]; 1712 return dic; 1713} 1714 1715- (void)netServiceDidResolveAddress:(NSNetService *)service { 1716 1717 [service retain]; 1718 [self stopCurrentResolve]; 1719 [self tableViewData]; 1720 [self.delegate browserViewController:self didResolveInstance:service]; 1721 [service release]; 1722} 1723*/ 1724 1725 1726//解析ip地址后初始化tableview试图 1727-(void)tableViewData{ 1728 //设备列表 1729 if (m_tableView) { 1730 [m_tableView removeFromSuperview]; 1731 } 1732 1733 //edited by hi.tan: 屏幕旋转处理 1734 //m_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 30, 320, 340)]; 1735 m_tableView = [[UITableView alloc]initWithFrame:CGRectZero]; 1736 // add by hi.tan 1737 [self showViewWithOrientation:self.interfaceOrientation]; 1738 1739 m_tableView.backgroundColor = [UIColor clearColor]; 1740 1741 m_tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 1742 m_tableView.delegate = self; 1743 m_tableView.dataSource = self; 1744 [self.view addSubview:m_tableView]; 1745 1746} 1747 1748- (void)cancelAction { 1749 [self.delegate browserViewController:self didResolveInstance:nil]; 1750} 1751 1752- (void)dealloc { 1753 // Cleanup any running resolve and free memory 1754 [self stopCurrentResolve]; 1755 [self.currentResolve release]; //add by hi.tan for mem leak 1756 [self.services release]; 1757 //self.services = nil; 1758 [self.netServiceBrowser stop]; 1759 self.netServiceBrowser = nil; 1760 [_searchingForServicesString release]; 1761 [_ownName release]; 1762 [_ownEntry release]; 1763 1764 [m_tableView release]; 1765 [m_toolView release]; 1766 [m_imageView release]; 1767 [m_hosBtn release]; 1768 // hi.tan add: 清理内存 1769 [m_wifiView release]; 1770 [m_wifilab release]; 1771 [m_hisLab release]; 1772 [_currentResolve release]; 1773 [_timer release]; 1774 //end hi.tan 1775 [m_alert release]; 1776#if !defined (__GENIE_IPHONE__) 1777 [popoverController release]; 1778#endif 1779 1780 //hi.tan: 下拉刷新 1781 _refreshHeaderView = nil; 1782 //hi.tan: 下拉刷新 1783 [super dealloc]; 1784} 1785 1786 1787//历史纪录跳转页面 1788-(void)showHistoryView{ 1789 HistoryViewController *history = [[HistoryViewController alloc]init]; 1790 [self.navigationController pushViewController:history animated:YES]; 1791 [history release]; 1792} 1793//点击图片,连续播放图片动画 1794-(void)onClickImage{ 1795 //重新加在数据 1796 UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 48, 48)]; 1797 imageView.animationImages = [NSArray arrayWithObjects: 1798 [UIImage imageNamed:@"one.png"], 1799 [UIImage imageNamed:@"two.png"], 1800 [UIImage imageNamed:@"three.png"], 1801 [UIImage imageNamed:@"four.png"], 1802 [UIImage imageNamed:@"five.png"], 1803 nil]; 1804 //动画间隔事件 1805 [imageView setAnimationDuration:1.0f]; 1806 //动画连播次数 1807 [imageView setAnimationRepeatCount:4]; 1808 //开始动画 1809 [imageView startAnimating]; 1810 [m_toolView addSubview:imageView]; 1811 [imageView release]; 1812 1813 UIImageView *imageArr = [[UIImageView alloc] initWithFrame:CGRectMake(55, 0, 220, 50)]; 1814 imageArr.animationImages = [NSArray arrayWithObjects: 1815 [UIImage imageNamed:@"1.png"], 1816 [UIImage imageNamed:@"2.png"], 1817 [UIImage imageNamed:@"3.png"], 1818 [UIImage imageNamed:@"4.png"], 1819 [UIImage imageNamed:@"5.png"], 1820 [UIImage imageNamed:@"6.png"], 1821 [UIImage imageNamed:@"7.png"], 1822 [UIImage imageNamed:@"8.png"], 1823 [UIImage imageNamed:@"9.png"], 1824 nil]; 1825 [imageArr setAnimationDuration:1.0f]; 1826 [imageArr setAnimationRepeatCount:3]; 1827 [imageArr startAnimating]; 1828 [imageArr setAlpha:0.7]; 1829 [m_toolView addSubview:imageArr]; 1830 [imageArr release]; 1831 1832 //当按刷新或搜索新设备的时候,只让DLNA去发现和搜索,不让bonjour重新搜索了,bonjour服务只最开始搜索一次,以后发现有新设备就添加,发现服务消失就删除的功能 1833 //[[BonjourServiceResolving GetBonjourResolvInstance] searchForServicesOfType:@"_ros-master._tcp" inDomain:@"local"]; 1834 //上面这行代码在添加DLNA探测对方是否在线的功能近来后,不需要了,主要靠bonjour服务和DLNA来添加和删除设备 1835 //DLNADelegation::GetInstance()->refreshDevices((deejay::DLNACore::FlushMode)0);//该函数会将dlna底层的设备列表给清空 1836 DLNADelegation::GetInstance()->searchDevices(); 1837 // 发送一个搜索的广播消息出去,搜索设备 1838 //NSLog(@"图片被点击!"); 1839 [m_tableView reloadData]; 1840} 1841 1842//获取本设备连接的wifi名字 1843-(NSString *)getwifiName{ 1844 NSString *wifiStr = nil; 1845 CFArrayRef arrayRef = CNCopySupportedInterfaces(); 1846 NSArray *interfaces = (NSArray *)arrayRef; 1847 if (interfaces) { 1848 for (NSString *interfaceName in interfaces) { 1849 CFDictionaryRef dictRef = CNCopyCurrentNetworkInfo((CFStringRef)interfaceName); 1850 if (dictRef != NULL) { 1851 NSDictionary *networkInfo = (NSDictionary *)dictRef; 1852 wifiStr = [NSString stringWithFormat:@"%@",[networkInfo objectForKey:@"SSID"]]; //hi.tan for mem leak 1853 CFRelease(dictRef); 1854 } 1855 } 1856 CFRelease(arrayRef); 1857 } 1858 if(wifiStr == nil) 1859 { 1860 wifiStr = [NSString stringWithFormat:Localization_Mobile_Device_WIFI_NotEnable]; //hi.tan : localization for mem leak 1861 } 1862 return wifiStr; 1863} 1864@endZ2#import "BrowserViewController.h" 3#include <arpa/inet.h> 4#import <SystemConfiguration/SystemConfiguration.h> 5#import <SystemConfiguration/CaptiveNetwork.h> 6#import "HistoryViewController.h" 7#import "GenieModuleHelper.h" 8#import "BonjourServiceResolving.h" 9#import "GenieHelper.h" 10#import "GenieHelper_Statistics.h" 11#import "UDTDelegation.h" 12#import "BonjourTest.h" 13#import <AVFoundation/AVFoundation.h> 14#include <MobileCoreServices/MobileCoreServices.h> 15//#import "AVURLAsset.h" 16#import "DLNADelegation.h" 17#import "DLNACore.h" 18#import "UIImage+UIImageExt.h" 19#import "TextMessageViewController.h" 20#import "CheckButton.h" 21 22#define kProgressIndicatorSize 20.0 23 24// A category on NSNetService that's used to sort NSNetService objects by their name. 25@interface NSNetService (BrowserViewControllerAdditions) 26- (NSComparisonResult) localizedCaseInsensitiveCompareByName:(NSNetService *)aService; 27@end 28 29@implementation NSNetService (BrowserViewControllerAdditions) 30- (NSComparisonResult) localizedCaseInsensitiveCompareByName:(NSNetService *)aService { 31 return [[self name] localizedCaseInsensitiveCompare:[aService name]]; 32} 33@end 34 35 36@interface BrowserViewController() 37@property (nonatomic, retain, readwrite) NSNetService *ownEntry; 38@property (nonatomic, assign, readwrite) BOOL showDisclosureIndicators; 39@property (nonatomic, retain, readwrite) NSMutableArray *services; 40@property (nonatomic, retain, readwrite) NSNetServiceBrowser *netServiceBrowser; 41@property (nonatomic, retain, readwrite) NSNetService *currentResolve; 42@property (nonatomic, retain, readwrite) NSTimer *timer; 43@property (nonatomic, assign, readwrite) BOOL needsActivityIndicator; 44@property (nonatomic, assign, readwrite) BOOL initialWaitOver; 45 46@property(nonatomic)class UDTDelegation *delegation; 47 48- (void)stopCurrentResolve; 49- (void)initialWaitOver:(NSTimer *)timer; 50@end 51 52@implementation BrowserViewController 53 54@synthesize delegate = _delegate; 55@synthesize ownEntry = _ownEntry; 56@synthesize showDisclosureIndicators = _showDisclosureIndicators; 57@synthesize currentResolve = _currentResolve; 58@synthesize netServiceBrowser = _netServiceBrowser; 59@synthesize services = _services; 60@synthesize needsActivityIndicator = _needsActivityIndicator; 61@dynamic timer; 62@synthesize initialWaitOver = _initialWaitOver; 63 64@synthesize delegation = _delegation; 65@synthesize m_alert = m_alert; 66 67- (void) loadView 68{ 69 UIView * v = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 70 self.view = v; 71 [v release]; 72 [self.view setBackgroundColor:[UIColor blackColor]]; 73 74 //hi.tan: ios5,6,7 同一导航栏:添加一个刷新按钮,ios7用系统的,ios 5,6用图片自定义 75// if([UIDevice currentDevice].systemVersion.floatValue >= 7.0) 76// { 77// UIBarButtonItem * rightBtnItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(savingPowerModeSetting)]; 78// self.navigationItem.rightBarButtonItem = rightBtnItem; 79// [rightBtnItem release]; 80// } 81// else 82// { 83// //hi.tan:IOS6上用图片来显示 84// UIImage *tmpimage = [UIImage imageNamed:@"refresh.png"]; 85// UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 26, 26)]; 86// [btn setBackgroundImage:tmpimage forState:UIControlStateNormal]; 87// [btn addTarget:self action:@selector(savingPowerModeSetting) forControlEvents:UIControlEventTouchUpInside]; 88// UIBarButtonItem * rightBtnItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; 89// self.navigationItem.rightBarButtonItem = rightBtnItem; 90// [rightBtnItem release]; 91// [btn release]; 92// } 93 94 UIBarButtonItem * rightBtnItem = [[UIBarButtonItem alloc] initWithTitle:Localization_Wireless_InfoPage_Title style: UIBarButtonItemStylePlain target:self action:@selector(savingPowerModeSetting)]; 95 self.navigationItem.rightBarButtonItem = rightBtnItem; 96 [rightBtnItem release]; 97 //hi.tan: ios5,6,7 同一导航栏:添加一个刷新按钮,ios7用系统的,ios 5,6用图片自定义 98 99 //wifi显示视图: edited by hi.tan: 屏幕旋转ui的处理 100 m_wifiView = [[UIView alloc] initWithFrame:CGRectZero]; 101 102 if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) 103 { 104 m_wifiView.frame = CGRectMake(CGZero, CGZero, iOSDeviceScreenWidth, 30); 105 } 106 else if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) 107 { 108 m_wifiView.frame = CGRectMake(CGZero, CGZero, iOSDeviceScreenHeight, 30); 109 } 110 111 //添加label到views 112 m_wifilab = [[UILabel alloc]initWithFrame:CGRectMake(45, 5, 150, 20)]; 113 NSString *wifiName = [self getwifiName]; 114 //添加wifi图标 115 UIImageView *wifiImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, 20, 20)]; 116 if([wifiName isEqualToString:Localization_Mobile_Device_WIFI_NotEnable]) 117 { 118 wifiImage.image = [UIImage imageNamed:@"signal_level_0.png"]; 119 } 120 else 121 { 122 wifiImage.image = [UIImage imageNamed:@"signal_level_4.png"]; 123 } 124 [m_wifiView addSubview:wifiImage]; 125 [wifiImage release]; 126 127 m_wifilab.text = wifiName; 128 m_wifilab.font = [UIFont systemFontOfSize:12.0]; 129 m_wifilab.textColor = [UIColor whiteColor]; 130 m_wifilab.backgroundColor = [UIColor clearColor]; 131 [m_wifiView addSubview:m_wifilab]; 132 133 m_wifiView.backgroundColor = [UIColor grayColor]; 134 // [views setAlpha:0.5]; 135 [self.view addSubview:m_wifiView]; 136 137 138 139 self.title = Localization_HP_Turbo_Transfer_Function_DeviceList_Title; 140 141 //toolbar视图: edited by hi.tan : 屏幕旋转处理 142 m_toolView = [[UIView alloc] initWithFrame:CGRectZero]; 143 if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) 144 { 145 m_toolView.frame = CGRectMake(CGZero, iOSDeviceScreenHeight-iOSStatusBarHeight-Navi_Bar_Height_Portrait - 50, iOSDeviceScreenWidth, 50); 146 } 147 else if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) 148 { 149 m_toolView.frame = CGRectMake(CGZero, iOSDeviceScreenWidth-iOSStatusBarHeight-Navi_Bar_Height_Landscape - 50, iOSDeviceScreenHeight, 50); 150 } 151 152 153 [m_toolView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"0.png"]]]; 154 [self.view addSubview:m_toolView]; 155 156 m_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 48, 48)]; 157 m_imageView.image = [UIImage imageNamed:@"one.png"]; 158 //imageview绑定点击事件 159 m_imageView.userInteractionEnabled=YES; 160 UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage)]; 161 [m_imageView addGestureRecognizer:singleTap]; 162 [singleTap release]; 163 [m_toolView addSubview:m_imageView]; 164 //得到设备名称 165 UILabel *deviceLab = [[UILabel alloc] initWithFrame:CGRectMake(60, 5, 200, 40)]; 166 deviceLab.textColor = [UIColor whiteColor]; 167 deviceLab.backgroundColor = [UIColor clearColor]; 168 deviceLab.text = [[UIDevice currentDevice] name]; 169 [m_toolView addSubview:deviceLab]; 170 [deviceLab release]; 171 172 m_hosBtn = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; 173 m_hosBtn.frame= CGRectZero; 174 // add by hi.tan: 屏幕旋转处理 175 if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){ 176 m_hosBtn.frame= CGRectMake(iOSDeviceScreenWidth - 32 - 6 , 5, 32, 30); 177 } 178 else if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){ 179 m_hosBtn.frame= CGRectMake(iOSDeviceScreenHeight - 32 - 6, 5, 32, 30); 180 } 181 // 182 [m_hosBtn setBackgroundImage:[UIImage imageNamed:@"turbo_history_small.png"] forState:UIControlStateNormal]; 183 [m_hosBtn addTarget:self action:@selector(showHistoryView) forControlEvents:UIControlEventTouchUpInside]; 184 [m_toolView addSubview:m_hosBtn]; 185 186 //edited by hi.tan: 屏幕旋转处理 187 //m_hisLab = [[UILabel alloc] initWithFrame:CGRectMake(283, 30, 25, 15)]; 188 m_hisLab = [[UILabel alloc] initWithFrame:CGRectZero]; 189 if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){ 190 m_hisLab.frame= CGRectMake(iOSDeviceScreenWidth - 42, 33, 40, 15); 191 } 192 else if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){ 193 m_hisLab.frame= CGRectMake(iOSDeviceScreenHeight - 42, 33, 40, 15); 194 } 195 196 m_hisLab.backgroundColor = [UIColor clearColor]; 197 m_hisLab.text = Localization_HP_Turbo_Transfer_Function_History_Title; 198 m_hisLab.font = [UIFont systemFontOfSize:10.0]; 199 m_hisLab.textColor =[UIColor whiteColor]; 200 m_hisLab.textAlignment = NSTextAlignmentCenter; 201 [m_toolView addSubview:m_hisLab]; 202 203 [self tableViewData]; 204 [m_tableView reloadData]; 205 206} 207 208//hi.tan: 更新wifi名称 209-(void)updateWifiNameLabel 210{ 211#ifdef __GENIE_IPHONE__ 212 GenieiPhoneiPodAppDelegate *appDelegate = (GenieiPhoneiPodAppDelegate *)[UIApplication sharedApplication].delegate; 213#else 214 GenieiPadAppDelegate *appDelegate = (GenieiPadAppDelegate *)[UIApplication sharedApplication].delegate; 215#endif 216 217 NSString *WIFI_SSID = [appDelegate getCurrentWIFI_SSID]; 218 m_wifilab.text = WIFI_SSID;//[self getwifiName]; 219 220 [m_tableView reloadData]; 221} 222 223 224-(void)viewDidLoad 225{ 226 [super viewDidLoad]; 227 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) 228 { 229 /* 230 增加iOS 7适配。 231 232 2013-10-10 by 梁平贤 233 */ 234 self.edgesForExtendedLayout = UIRectEdgeNone; 235 } 236 //[self WaitMessageDialogShow:Localization_FileTransfer_Wait_Msg]; 237 //[self onClickImage]; 238 239 //注册一个切换wifi更新wifi名称的通知 240 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateWifiNameLabel) name:@"updateWifiName" object:nil]; 241 //hi.tan: 下拉刷新功能 242 if (_refreshHeaderView == nil) { 243 244 EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:m_tableView.bounds]; 245 246 //上移 247 CGPoint center=view.center; 248 center.y-=m_tableView.bounds.size.height; 249 view.center=center; 250 251 view.delegate = self; 252 [m_tableView addSubview:view]; 253 _refreshHeaderView = view; 254 [view release]; 255 256 } 257 // update the last update date 258// [_refreshHeaderView refreshLastUpdatedDate]; 259// NSDate* date = [_refreshHeaderView getDateTime]; 260// m_lasttime = [date timeIntervalSince1970]*1; 261 //第一次进来,就进行刷新 262 m_tableView.contentOffset = CGPointMake(0, -65); 263 [_refreshHeaderView egoRefreshScrollViewDidEndDragging:m_tableView]; 264 [_refreshHeaderView egoRefreshScrollViewDidScroll:m_tableView]; 265 266 //hi.tan: 下拉刷新功能 267 //hi.tan: 检测文件传输端口是否监听成功 268 //[[GenieHelper GetInstance] newFileTransferPortListen]; 269} 270 271- (void)viewDidUnload 272{ 273 _refreshHeaderView=nil; 274} 275 276#pragma mark - 277#pragma mark Data Source Loading / Reloading Methods 278 279- (void)reloadTableViewDataSource{ 280 281 // should be calling your tableviews data source model to reload 282 // put here just for demo 283 284 [self refreshDeviceList]; 285 _reloading = YES; 286 287} 288 289- (void)doneLoadingTableViewData{ 290 291 // model should call this when its done loading 292 _reloading = NO; 293 [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:m_tableView]; 294 295} 296 297 298#pragma mark - 299#pragma mark UIScrollViewDelegate Methods 300 301- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ 302 303 [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView]; 304 305} 306 307- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ 308 309 [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView]; 310 311} 312 313 314#pragma mark - 315#pragma mark EGORefreshTableHeaderDelegate Methods 316 317- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view 318{ 319 [self reloadTableViewDataSource]; 320 [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0]; 321} 322 323- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{ 324 325 return _reloading; // should return if data source model is reloading 326 327} 328 329- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{ 330 331 return [NSDate date]; // should return date data source was last changed 332 333} 334#pragma mark EGORefreshTableHeaderDelegate Methods 335 336 337-(void)WaitMessageDialogShow:(NSString *)msg 338{ 339 if (m_alert != nil) 340 { 341 [m_alert release]; 342 m_alert = nil; 343 } 344 345 346 m_alert = [[[UIAlertView alloc] initWithTitle:msg 347 message:nil 348 delegate:self 349 cancelButtonTitle:nil 350 otherButtonTitles: nil] autorelease]; 351 [m_alert setFrame:CGRectMake(self.view.frame.size.width / 2 - 20, self.view.frame.size.height /2 - 60, 280, 120)]; 352 353 [m_alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES]; 354 355 UIActivityIndicatorView * aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 356 aiv.center = CGPointMake(m_alert.bounds.size.width/2.0f, m_alert.bounds.size.height/2.0f + 16); 357 [aiv startAnimating]; 358 [m_alert addSubview:aiv]; 359 [aiv release]; 360 361 [self performSelectorOnMainThread:@selector(dismissMyAlert) withObject:nil waitUntilDone:YES]; 362} 363 364- (void) dismissMyAlert 365{ 366 if(m_alert != nil) 367 { 368 [m_alert dismissWithClickedButtonIndex:99 animated:YES]; 369 m_alert = nil; 370 } 371} 372 373- (id)initWithTitle:(NSString *)title showDisclosureIndicators:(BOOL)show showCancelButton:(BOOL)showCancelButton { 374 375 m_alert = nil; 376// if ((self = [super initWithStyle:UITableViewStylePlain])) { 377 self.currentResolve = [[NSNetService alloc] init]; 378 self.title = title; 379 _services = [[NSMutableArray alloc] init]; 380 self.showDisclosureIndicators = show; 381 if (showCancelButton) { 382 // add Cancel button as the nav bar's custom right view 383 UIBarButtonItem *addButton = [[UIBarButtonItem alloc] 384 initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAction)]; 385 self.navigationItem.rightBarButtonItem = addButton; 386 [addButton release]; 387 } 388 389 // Make sure we have a chance to discover devices before showing the user that nothing was found (yet) 390 [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(initialWaitOver:) userInfo:nil repeats:NO]; 391// } 392 //bonjour service updated by self or DLNA 393 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bonjourServersUpdate:) name:@"BonjourChange" object:nil]; 394 [self.currentResolve release]; 395 return self; 396} 397 398 399// hi.tan: 添加修改对屏幕旋转的处理 400- (void) viewWillAppear:(BOOL)animated 401{ 402 [super viewWillAppear:animated]; 403 [self showViewWithOrientation:self.interfaceOrientation]; 404} 405 406- (BOOL)shouldAutorotate 407{ 408 return YES; 409} 410- (NSUInteger)supportedInterfaceOrientations 411{ 412 return UIInterfaceOrientationMaskAll; 413} 414 415- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 416{ 417 return YES; 418} 419 420- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 421{ 422 [self showViewWithOrientation:toInterfaceOrientation]; 423} 424- (void) showViewWithOrientation:(UIInterfaceOrientation)orientation 425{ 426 427 //tableView frame.size.y = 30: 为上面的无线标签留出来的 428 //高度减去50,是为底部的toolbar留出空间 429 if (UIInterfaceOrientationIsPortrait(orientation)) 430 { 431 m_tableView.frame = CGRectMake(CGZero, 30, iOSDeviceScreenWidth, iOSDeviceScreenHeight-iOSStatusBarHeight-Navi_Bar_Height_Portrait - 50 -30); 432 m_toolView.frame = CGRectMake(CGZero, iOSDeviceScreenHeight-iOSStatusBarHeight-Navi_Bar_Height_Portrait - 50, iOSDeviceScreenWidth, 50); 433 m_wifiView.frame = CGRectMake(CGZero, CGZero, iOSDeviceScreenWidth, 30); 434 m_hosBtn.frame= CGRectMake(iOSDeviceScreenWidth - 32-6, 5, 32, 30); 435 m_hisLab.frame= CGRectMake(iOSDeviceScreenWidth - 42, 33, 40, 15); 436 } 437 else if (UIInterfaceOrientationIsLandscape(orientation)) 438 { 439 m_tableView.frame = CGRectMake(CGZero, 30, iOSDeviceScreenHeight, iOSDeviceScreenWidth-iOSStatusBarHeight-Navi_Bar_Height_Landscape - 50 -30); 440 m_toolView.frame = CGRectMake(CGZero, iOSDeviceScreenWidth-iOSStatusBarHeight-Navi_Bar_Height_Landscape - 50, iOSDeviceScreenHeight, 50); 441 m_wifiView.frame = CGRectMake(CGZero, CGZero, iOSDeviceScreenHeight, 30); 442 m_hosBtn.frame= CGRectMake(iOSDeviceScreenHeight - 32-6, 5, 32, 30); 443 m_hisLab.frame= CGRectMake(iOSDeviceScreenHeight - 42, 33, 40, 15); 444 } 445 446} 447// hi.tan: 添加修改对屏幕旋转的处理 448 449 450// 右上角添加的刷新按钮 451-(void)refreshDeviceList 452{ 453 //2014-4-21: 做一下监测,发现当前上层ui没有设备的时候,就只需要去搜索设备就ok了 454 if([[[BonjourServiceResolving GetBonjourResolvInstance] getIPArray] count] != 0) 455 { 456 [[BonjourServiceResolving GetBonjourResolvInstance] deleteAllDeviceList]; 457 //HI.tan: 2014-4-10: 刷新按钮将DLNA设备发现的底层保存的设备一同给删除掉 458 DLNADelegation::GetInstance()->refreshDevices((deejay::DLNACore::FlushMode)0); 459 } 460 DLNADelegation::GetInstance()->searchDevices(); 461 [[BonjourServiceResolving GetBonjourResolvInstance] searchForServicesOfType:@"_ros-master._tcp" inDomain:@"local"]; 462} 463 464 465-(void)savingPowerModeSetting 466{ 467 468// m_tableView.contentOffset = CGPointMake(0, -65); 469// [_refreshHeaderView egoRefreshScrollViewDidEndDragging:m_tableView]; 470// [_refreshHeaderView egoRefreshScrollViewDidScroll:m_tableView]; 471// return; 472 473 474 if([UIDevice currentDevice].systemVersion.floatValue >= 7.0) 475 { 476 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil 477 message:NSLocalizedString(@"Enable Power Saving Mode Message",nil) 478 delegate:self 479 cancelButtonTitle:nil 480 otherButtonTitles:Localization_Close,nil]; 481 482 UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 260, 40)]; 483 bgView.backgroundColor = [UIColor clearColor]; 484 485 CheckButton *checkButton = [[CheckButton alloc ] initWithFrame : CGRectMake (22, 0, 240, 32)]; 486 checkButton.value =[[ NSNumber alloc ] initWithInt:1]; 487 // 把按钮设置为单选按钮样式 488 checkButton. style = CheckButtonStyleBox; 489 checkButton.checked = [GenieHelper getSavingPowerModeFlag]; 490 checkButton.enabled = YES; 491 checkButton.label.text = NSLocalizedString(@"Enable Power Saving Mode",nil); 492 checkButton.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14]; 493 checkButton.label.textColor = [UIColor blackColor]; 494 checkButton.delegate = self; 495 [bgView addSubview:checkButton]; 496 [alert setValue:bgView forKey:@"accessoryView"]; 497 [checkButton release]; 498 [bgView release]; 499 [alert show]; 500 [alert release]; 501 } 502 else 503 { 504 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"\n\n" 505 message:NSLocalizedString(@"Enable Power Saving Mode Message",nil) 506 delegate:self 507 cancelButtonTitle:nil 508 otherButtonTitles:Localization_Close,nil]; 509 510 UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 12, 260, 40)]; 511 bgView.backgroundColor = [UIColor clearColor]; 512 513 CheckButton *checkButton = [[CheckButton alloc ] initWithFrame : CGRectMake (22, 0, 240, 32)]; 514 checkButton.value =[[ NSNumber alloc ] initWithInt:1]; 515 // 把按钮设置为单选按钮样式 516 checkButton. style = CheckButtonStyleBox; 517 checkButton.checked = [GenieHelper getSavingPowerModeFlag]; 518 checkButton.enabled = YES; 519 checkButton.label.text = NSLocalizedString(@"Enable Power Saving Mode",nil); 520 checkButton.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14]; 521 checkButton.label.textColor = [UIColor whiteColor]; 522 checkButton.delegate = self; 523 [bgView addSubview:checkButton]; 524 [alert addSubview:bgView]; 525 [checkButton release]; 526 [bgView release]; 527 [alert show]; 528 [alert release]; 529 } 530} 531 532 533//hi.tan: 省电模式的check按钮后需要在这里做处理,通过GenieHelper保存到本地,作为全局变量攻其它地方使用 534-(void)checkButtonClicked:(CheckButton *)button 535{ 536 CheckButton *btn = button; 537 if([btn checked]) 538 {8af249539#ifdef UserBehaviourZ540 [GenieAdvanceInfoStatistics GetInstance].turboTransfer.TT6++; 541#endif 542 543 291400544 [btn setChecked:NO];Z545 [GenieHelper setSavingPowerModeFlag:[btn checked]]; 546 //NSLog(@"Bool Checked = %d",[btn checked]); 547 } 548 else 549 {8af249550#ifdef UserBehaviourZ551 [GenieAdvanceInfoStatistics GetInstance].turboTransfer.TT5++; 552#endif291400553 [btn setChecked:YES];Z554 [GenieHelper setSavingPowerModeFlag:[btn checked]]; 555 //NSLog(@"Bool Checked = %d",[btn checked]); 556 } 557} 558 559// 当检测到bonjour服务或者DLNA服务的时候,即当bonReslv中的—IP_arry被更新的时候,同时更新这边tableview的数据 560- (void)bonjourServersUpdate:(NSNotification *)no 561{ 562 [m_tableView reloadData]; 563} 564 565- (void)turboTransferDeviceListUpdate 566{ 567 [m_tableView reloadData]; 568} 569 570 571- (NSString *)searchingForServicesString { 572 return _searchingForServicesString; 573} 574 575// Holds the string that's displayed in the table view during service discovery. 576- (void)setSearchingForServicesString:(NSString *)searchingForServicesString 577{ 578 if (_searchingForServicesString != searchingForServicesString) { 579 [_searchingForServicesString release]; 580 _searchingForServicesString = [searchingForServicesString copy]; 581 582 // If there are no services, reload the table to ensure that searchingForServicesString appears. 583 if ([self.services count] == 0) { 584 [m_tableView reloadData]; 585 } 586 } 587} 588 589- (NSString *)ownName 590{ 591 return _ownName; 592} 593 594// Holds the string that's displayed in the table view during service discovery. 595- (void)setOwnName:(NSString *)name { 596 if (_ownName != name) { 597 _ownName = [name copy]; 598 599 if (self.ownEntry) 600 [self.services addObject:self.ownEntry]; 601 602 NSNetService* service; 603 604 for (service in self.services) { 605 if ([service.name isEqual:name]) { 606 self.ownEntry = service; 607 [_services removeObject:service]; 608 609 break; 610 } 611 } 612 613 [m_tableView reloadData]; 614 } 615} 616 617- (NSTimer *)timer { 618 return _timer; 619} 620 621// When this is called, invalidate the existing timer before releasing it. 622- (void)setTimer:(NSTimer *)newTimer { 623 [_timer invalidate]; 624 [newTimer retain]; 625 [_timer release]; 626 _timer = newTimer; 627} 628 629- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 630 return 1; 631} 632 633- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 634 //NSUInteger count = [self.services count]; 635 NSUInteger count = [[[BonjourServiceResolving GetBonjourResolvInstance] getIPArray] count]; 636 637 if (count == 0 && self.searchingForServicesString && self.initialWaitOver) 638 return 1; 639 640 return count; 641} 642 643- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 644{ 645#ifdef __GENIE_IPHONE__ 646 return 49; 647#else 648 return 55; 649#endif 650} 651 652- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 653 654 static NSString *tableCellIdentifier = @"UITableViewCell"; 655 UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:tableCellIdentifier]; 656 if (cell == nil) { 657 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableCellIdentifier] autorelease]; 658 } 659 660 // ios7 默认背景颜色为白色 661 cell.backgroundColor = [UIColor clearColor]; 662 663 //NSUInteger count = [self.services count]; 664 NSMutableArray *IParray = [NSMutableArray arrayWithArray:[[BonjourServiceResolving GetBonjourResolvInstance] getIPArray]]; 665 666 NSUInteger count = [IParray count]; 667 668 if (count == 0) 669 { 670 cell.textLabel.text = self.searchingForServicesString; 671 cell.textLabel.textColor = [UIColor whiteColor]; 672 cell.accessoryType = UITableViewCellAccessoryNone; 673 if (cell.accessoryView) 674 cell.accessoryView = nil; 675 return cell; 676 } 677 // Set up the text for the cell 678 NSDictionary *dic = nil; 679 if(indexPath.row < count) 680 { 681 dic = [IParray objectAtIndex:indexPath.row]; 682 } 683 684 if(dic == nil) 685 { 686 cell.textLabel.text = self.searchingForServicesString; 687 cell.textLabel.textColor = [UIColor whiteColor]; 688 cell.accessoryType = UITableViewCellAccessoryNone; 689 if (cell.accessoryView) 690 cell.accessoryView = nil; 691 return cell; 692 } 693 694 NSString *ipstring = [dic objectForKey:@"ipAddr"]; 695 cell.detailTextLabel.text = ipstring; 696 cell.detailTextLabel.textColor = [UIColor whiteColor]; 697 698 NSString *serviceName = [dic objectForKey:@"serviceName"]; 699 NSString *serviceNameToDisplay = serviceName; 700 701 702// if([serviceNameToDisplay length] > 20) 703// { 704// //serviceName __NSCFString * @"“pingxian_liang”的 iPod[iPodtouch]" 0x16017cf0 705// 706// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"_" withString:@""]; 707// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@" " withString:@""]; 708// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"." withString:@"["]; 709// 710// //int index = serviceName 711// NSRange range; 712// memset(&range,0,sizeof(range)); 713// range = [serviceNameToDisplay rangeOfString:@"["]; 714// 715// if(range.location != 0 && range.location <= [serviceNameToDisplay length]) 716// { 717// serviceNameToDisplay = [serviceNameToDisplay substringToIndex:range.location]; 718// } 719// 720// if([serviceNameToDisplay length] > 20) 721// { 722// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"-" withString:@"["]; 723// NSRange range; 724// memset(&range,0,sizeof(range)); 725// range = [serviceNameToDisplay rangeOfString:@"["]; 726// 727// if(range.location != 0 && range.location <= [serviceNameToDisplay length]) 728// { 729// serviceNameToDisplay = [serviceNameToDisplay substringToIndex:range.location]; 730// } 731// } 732// 733// if([serviceNameToDisplay length] > 20) 734// { 735// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"_" withString:@""]; 736// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@" " withString:@""]; 737// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"." withString:@""]; 738// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"\"" withString:@""]; 739// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"\"" withString:@""]; 740// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"“" withString:@""]; 741// serviceNameToDisplay = [serviceNameToDisplay stringByReplacingOccurrencesOfString:@"”" withString:@""]; 742// } 743// 744// if([serviceNameToDisplay length] >= 21) 745// { 746// serviceNameToDisplay = [serviceNameToDisplay substringToIndex:20]; 747// } 748// } 749 750 751 NSRange range = [serviceNameToDisplay rangeOfString:@"["]; 752 if(range.location > 0 && range.location <= [serviceNameToDisplay length]) 753 { 754 serviceNameToDisplay = [serviceNameToDisplay substringToIndex:range.location]; 755 } 756 757 cell.textLabel.text = serviceNameToDisplay; 758 cell.textLabel.textColor = [UIColor whiteColor]; 759 cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold"size:20]; //加粗 760 761 762 763 764 //cell.imageView.image = [UIImage imageNamed:@"defaultserver.png"]; //device_iphone_icon.png 765 NSString *serviceNameLowcase = [serviceName lowercaseString]; 766 UIImage *image = nil; 767 if ([serviceNameLowcase rangeOfString:@"iphone"].length) 768 { 769 image = [UIImage imageNamed:@"device_iphone_icon.png"]; 770 } 771 else if ([serviceNameLowcase rangeOfString:@"ipad"].length) 772 { 773 image = [UIImage imageNamed:@"device_ipad_icon.png"]; 774 } 775 else if ([serviceNameLowcase rangeOfString:@"ipod"].length) 776 { 777 image = [UIImage imageNamed:@"device_ipod_icon.png"]; 778 } 779 else if ([serviceNameLowcase rangeOfString:@"androidtablet"].length) 780 { 781 image = [UIImage imageNamed:@"device_androidtablet_icon.png"]; 782 } 783 else if ([serviceNameLowcase rangeOfString:@"androidphone"].length) 784 { 785 image = [UIImage imageNamed:@"device_androidphone_icon.png"]; 786 } 787 else if ([serviceNameLowcase rangeOfString:@"androiddevice"].length) 788 { 789 image = [UIImage imageNamed:@"device_androiddevice_icon.png"]; 790 } 791 else if ([serviceNameLowcase rangeOfString:@"mac-mini"].length) 792 { 793 image = [UIImage imageNamed:@"device_imac_icon.png"]; 794 } 795 else if ([serviceNameLowcase rangeOfString:@"imac-mini"].length) 796 { 797 image = [UIImage imageNamed:@"device_macmini_icon.png"]; 798 } 799 else if ([serviceNameLowcase rangeOfString:@"imac"].length) 800 { 801 image = [UIImage imageNamed:@"device_imac_icon.png"]; 802 } 803 else if ([serviceNameLowcase rangeOfString:@"window"].length) 804 { 805 image = [UIImage imageNamed:@"device_windowspc_icon.png"]; 806 } 807 else if ([serviceNameLowcase rangeOfString:@"amazonkindle"].length) 808 { 809 image = [UIImage imageNamed:@"device_kindle_icon.png"]; 810 } 811 else 812 { 813 NSData *data = UIImagePNGRepresentation([UIImage imageNamed:@"defaultserver.png"]); 814 image = (UIImage *)[ UIImage imageWithData:data scale:(CGFloat)40/72]; 815 816 //image = [UIImage imageNamed:@"defaultserver.png"]; 817 818 } 819 820 if(image == nil) 821 { 822 823 //image = [UIImage imageNamed:@"defaultserver.png"]; 824 NSData *data = UIImagePNGRepresentation([UIImage imageNamed:@"defaultserver.png"]); 825 image = (UIImage *)[ UIImage imageWithData:data scale:(CGFloat)40/72]; 826 } 827 828 829 //cell.imageView.image = image; 830 831// if (self.needsActivityIndicator /*&& self.currentResolve == service*/) { 832// if (!cell.accessoryView) { 833// CGRect frame = CGRectMake(0.0, 0.0, kProgressIndicatorSize, kProgressIndicatorSize); 834// UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithFrame:frame]; 835// [spinner startAnimating]; 836// spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; 837// [spinner sizeToFit]; 838// spinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | 839// UIViewAutoresizingFlexibleRightMargin | 840// UIViewAutoresizingFlexibleTopMargin | 841// UIViewAutoresizingFlexibleBottomMargin); 842// cell.accessoryView = spinner; 843// [spinner release]; 844// } 845// } else if (cell.accessoryView) { 846// cell.accessoryView = nil; 847// } 848 849 //NSString * imgStr = cell.textLabel.text; 850#ifdef __GENIE_IPHONE__ 851 UIImage * img = image;//[UIImage imageNamed:lanDeviceInfo.icon]; 852 UIImage * icon = nil; 853 UIGraphicsBeginImageContext(CGSizeMake(37.0f, 37.0f)); 854 CGRect rec = CGRectMake(0, 0, 37.0f, 37.0f); 855 [img drawInRect:rec]; 856 icon = UIGraphicsGetImageFromCurrentImageContext(); 857 UIGraphicsEndImageContext(); 858 cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold"size:14];//[UIFont boldSystemFontOfSize:14]; 859 cell.imageView.image = icon; 860#else 861 cell.imageView.image = image; 862#endif 863 864 return cell; 865 866} 867 868- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { 869 870 if ([[[BonjourServiceResolving GetBonjourResolvInstance] getIPArray] count] == 0) 871 return nil; 872 873 return indexPath; 874} 875 876- (void)stopCurrentResolve { 877 878 self.needsActivityIndicator = NO; 879 self.timer = nil; 880 881 [self.currentResolve stop]; 882 //[self.currentResolve release]; //add by hi.tan for mem leak 883 self.currentResolve = nil; 884} 885 886- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 887 888 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 889 //hi.tan:文件拾取器 890 UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:Localization_FileTransfer_Select_Send_File_Type delegate:self cancelButtonTitle:Localization_Cancel destructiveButtonTitle:Localization_FileTransfer_File_Photo otherButtonTitles:Localization_FileTransfer_File_Video,Localization_FileTransfer_File_History, nil];//Localization_FileTransfer_File_Text 891 actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic; 892 //CGRect rect = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + self.view.frame.size.height/2, self.view.frame.size.width, self.view.frame.size.height/2); 893 [actionSheet showInView:self.view]; 894 //[actionSheet showFromRect:rect inView:self.view animated:NO]; 895 //[actionSheet showFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:NO]; 896 [actionSheet release]; 897 898 NSMutableArray *IParray = [NSMutableArray arrayWithArray:[[BonjourServiceResolving GetBonjourResolvInstance] getIPArray]]; 899 900 NSMutableDictionary *dic = nil; 901 if(indexPath.row < [IParray count]) 902 { 903 dic = [IParray objectAtIndex:indexPath.row]; 904 [PlistManipulate setDeviceMess:dic]; 905 } 906 [pool release]; 907} 908 909- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ 910 switch (buttonIndex) { 911 case 0://照片:可以选多张8af249912#ifdef UserBehaviourZ913 [GenieAdvanceInfoStatistics GetInstance].turboTransfer.TT4++; 914#endif291400915 [self pickMultiplePhotos];Z916 break; 917 case 1://视频:只能一次选择一个8af249918#ifdef UserBehaviourZ919 [GenieAdvanceInfoStatistics GetInstance].turboTransfer.TT3++; 920#endif291400921 [self pickSingleVideoFile];Z922 break; 923// case 2://剪切板 924// [self openMessage]; 925 break; 926 case 2://3://历史文件 927 [self openHistory]; 928 break; 929 default: 930 //取消 931 break; 932 } 933} 934//跳转到剪切板 935-(IBAction)openMessage{ 936 TextMessageViewController *messageView = [[TextMessageViewController alloc] init]; 937 //MessageViewController *messageView = [[MessageViewController alloc] init]; 938 //NSDictionary *dic = [PlistManipulate getDeviceMessage]; 939 //messageView.deviceDic = dic; 940 [self.navigationController pushViewController:messageView animated:YES]; 941 [messageView release]; 942} 943 944 945//跳转到历史纪录页面 946-(IBAction)openHistory{ 947 HistoryViewController *history = [[HistoryViewController alloc]init]; 948 history.isToSelectFileForTransfer = YES; 949 history.delegate = self; 950 //[self.navigationController pushViewController:history animated:YES]; 951 //hi.tan: 在IOS8上的特殊处理 952 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 953 { 954#ifdef __GENIE_IPHONE__ 955 [self.navigationController pushViewController:history animated:YES]; 956#else 957 dispatch_async(dispatch_get_main_queue(), ^{ 958 [self.navigationController pushViewController:history animated:YES]; 959 }); 960#endif 961 } 962 else 963 { 964 [self.navigationController pushViewController:history animated:YES]; 965 } 966 //hi.tan: 在IOS8上的特殊处理 967 [history release]; 968} 969 970#pragma mark - HistoryViewControllerdelegate 971- (void)tellTheTransferFileName:(NSString *)fileName andFilePath:(NSString *)filePath{ 972 //_myFileTransfer = [[FileTransferViewController alloc] init]; 973 // add by hi.tan: 974 [FileTransferViewController ReleaseInstance]; 975 FileTransferViewController *viewController = [FileTransferViewController SharedFileTransfer]; 976 NSDictionary *dic = [PlistManipulate getDeviceMessage]; 977 NSString *name = [[UIDevice currentDevice] name]; 978 viewController.sendIp = [NSString stringWithString:[dic objectForKey:@"ipAddr"]]; 979 viewController.sendDeviceName = name; 980 viewController.receiveDeviceName = [NSString stringWithString:[dic objectForKey:@"serviceName"]]; 981 //设置为1 为发送标记 982 viewController.fileFlag = [NSString stringWithFormat:@"1"]; 983 //发送文件 984 985 [viewController.imageUrls removeAllObjects]; 986 //[viewController.imageUrls addObject:filePath]; 987 NSData *data = [NSData dataWithContentsOfFile:filePath]; 988 NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 989 NSString * documentsDirectory = [paths objectAtIndex:0]; 990 NSString * sendingFileDir = [documentsDirectory stringByAppendingPathComponent:@"Sent"]; 991 992 NSFileManager *fileManager = [NSFileManager defaultManager]; 993 BOOL isDir = FALSE; 994 BOOL isDirExist = [fileManager fileExistsAtPath:sendingFileDir isDirectory:&isDir]; 995 if(!(isDirExist && isDir)) 996 { 997 BOOL bCreateDir = [fileManager createDirectoryAtPath:sendingFileDir withIntermediateDirectories:YES attributes:nil error:nil]; 998 if(!bCreateDir){ 999 NSLog(@"Create Audio Directory Failed."); 1000 return; 1001 } 1002 NSLog(@"%@",sendingFileDir); 1003 1004 NSString * sendingFilePath = [sendingFileDir stringByAppendingPathComponent:fileName]; 1005 [data writeToFile:sendingFilePath atomically:YES]; 1006 [viewController.imageUrls addObject:sendingFilePath]; 1007 } 1008 else 1009 { 1010 NSString *sendingFilePath = [sendingFileDir stringByAppendingPathComponent:fileName]; 1011 [data writeToFile:sendingFilePath atomically:YES]; 1012 [viewController.imageUrls addObject:sendingFilePath]; 1013 } 1014 1015 [self.navigationController pushViewController:viewController animated:YES]; 1016} 1017 1018 1019// add by hi.tan for :多个图片文件拾取器 1020#pragma mark multi photos picker controller and delegation 1021- (IBAction)pickSinglePhoto 1022{ 1023// QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init]; 1024// imagePickerController.delegate = self; 1025// 1026// UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePickerController]; 1027// [self presentViewController:navigationController animated:YES completion:NULL]; 1028// [imagePickerController release]; 1029// [navigationController release]; 1030} 1031 1032- (IBAction)pickMultiplePhotos 1033{ 1034 QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init]; 1035 // add by hi.tan : 照片和视频文件类型选取分开 1036 NSInteger index = 0; 1037 1038 if(index == 0){ // 照片 1039 imagePickerController.filterType = QBImagePickerFilterTypeAllPhotos; 1040 imagePickerController.title = @"Photos"; 1041 } 1042 else if(index == 1){ //视频 1043 1044 imagePickerController.filterType = QBImagePickerFilterTypeAllVideos; 1045 imagePickerController.title = @"Videos"; 1046 } 1047 1048 imagePickerController.delegate = self; 1049 imagePickerController.allowsMultipleSelection = YES; 1050 1051 imagePickerController.limitsMaximumNumberOfSelection = YES; 1052 imagePickerController.maximumNumberOfSelection = 10; // 添加一次选中图片最多张数限制为10 1053 1054 UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePickerController]; 1055 //[self presentViewController:navigationController animated:YES completion:NULL]; 1056 //hi.tan: 在IOS8上的特殊处理 1057 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 1058 { 1059 dispatch_async(dispatch_get_main_queue(), ^{ 1060 [self presentViewController:navigationController animated:YES completion:nil]; 1061 }); 1062 } 1063 else 1064 { 1065 [self presentViewController:navigationController animated:YES completion:nil]; 1066 } 1067 1068 [imagePickerController release]; 1069 [navigationController release]; 1070} 1071 1072 1073- (IBAction)pickWithLimitation 1074{ 1075// QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init]; 1076// imagePickerController.delegate = self; 1077// imagePickerController.allowsMultipleSelection = YES; 1078// 1079// imagePickerController.limitsMinimumNumberOfSelection = YES; 1080// imagePickerController.minimumNumberOfSelection = 6; 1081// 1082// UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePickerController]; 1083// [self presentViewController:navigationController animated:YES completion:NULL]; 1084// [imagePickerController release]; 1085// [navigationController release]; 1086} 1087 1088 1089-(IBAction)pickSingleVideoFile 1090{ 1091 UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 1092 imagePicker.delegate = self; 1093 imagePicker.allowsEditing = YES; 1094 1095//#ifdef __GENIE_IPHONE__ 1096// imagePicker.sourceType =UIImagePickerControllerSourceTypeSavedPhotosAlbum;// UIImagePickerControllerSourceTypePhotoLibrary; 1097// //hi.tan: 修改为只显示视频类型的文件供用户选择 1098// imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil]; 1099// 1100// [self presentModalViewController:imagePicker animated:YES]; 1101//// UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePicker]; 1102//// [self presentViewController:navigationController animated:YES completion:NULL]; 1103// [imagePicker release]; 1104// //[navigationController release]; 1105// 1106//#else 1107// imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;//UIImagePickerControllerSourceTypePhotoLibrary; 1108// imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil]; 1109// 1110// popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 1111// [popoverController presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 1112// [imagePicker release]; 1113//#endif 1114 1115#ifdef __GENIE_IPHONE__ 1116 imagePicker.sourceType =UIImagePickerControllerSourceTypeSavedPhotosAlbum;// UIImagePickerControllerSourceTypePhotoLibrary; 1117 //hi.tan: 修改为只显示视频类型的文件供用户选择 1118 imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil]; 1119 1120 [self presentModalViewController:imagePicker animated:YES]; 1121 [imagePicker release]; 1122 1123#else 1124 imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;//UIImagePickerControllerSourceTypePhotoLibrary; 1125 imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil]; 1126 popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 1127 //hi.tan: 在IOS8上的特殊处理 1128 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 1129 { 1130 dispatch_async(dispatch_get_main_queue(), ^{ 1131 [popoverController presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 1132 }); 1133 } 1134 else 1135 { 1136 [popoverController presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 1137 } 1138 //hi.tan: 在IOS8上的特殊处理 1139 [imagePicker release]; 1140#endif 1141} 1142 1143#pragma mark - 1144#pragma UIImagePickerController Delegate 1145//- (void)imagePickerController:(id)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 1146- (void)imagePickerController:(UIViewController *)picker didFinishPickingMediaWithInfo:(id)info 1147{ 1148 1149 UIViewController *pickView = picker; 1150 FileTransferViewController *viewController = [FileTransferViewController SharedFileTransfer]; 1151 1152 if([pickView isKindOfClass:[QBImagePickerController class]]) //说明是图片选择器 1153 { 1154 1155 //创建发送文件目录,并将图片移动到改目录 1156 NSString *date; 1157 NSMutableString *dateTmp; 1158 NSDateFormatter* formatter = [[NSDateFormatter alloc]init]; 1159 //hi.tan edited:修改传输文件的名称 1160 //[formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"]; 1161 [formatter setDateFormat:@"YYYYMMddhhmmss"]; 1162 date = [formatter stringFromDate:[NSDate date]]; 1163 1164 //hi.tan: 文件名称在iphone iOS8上后,date带有:号,统一都给去掉 1165 dateTmp = [[NSMutableString alloc] initWithString:date]; 1166 1167 NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:@":" 1168 options:NSRegularExpressionCaseInsensitive 1169 error:nil]; 1170 1171 [regex replaceMatchesInString:dateTmp options:0 range:NSMakeRange(0, [dateTmp length]) withTemplate:@""]; 1172 date = [NSString stringWithString:dateTmp]; 1173 [dateTmp release]; 1174 [regex release]; 1175 1176 [formatter release]; //hi.tan for mem leak 1177 1178 int totalPicked = [info count]; 1179 int i = 0; 1180 1181 [viewController.imageUrls removeAllObjects]; 1182 1183 for(i = 0; i<totalPicked;i++) 1184 { 1185 NSString *mediaType = [info[i] objectForKey:UIImagePickerControllerMediaType]; //ALAssetTypePhoto ALAssetTypeVideo 1186 1187 if ([mediaType isEqualToString:@"ALAssetTypePhoto"]) 1188 { 1189 // UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 1190 UIImage *image = [info[i] objectForKey:@"UIImagePickerControllerOriginalImage"]; 1191 NSLog(@"found an image"); 1192 1193 NSURL *imageFormate = [info[i] objectForKey:@"UIImagePickerControllerReferenceURL"]; 1194 1195 NSString *imageName = nil; 1196 1197 if([[imageFormate absoluteString] hasSuffix:@"JPG"] || [[imageFormate absoluteString] hasSuffix:@"jpg"]){ 1198 //NSLog(@"imageFormate = JPG"); 1199 imageName = [NSString stringWithFormat:@"%@%d.JPG",date,i]; 1200 } 1201 else if([[imageFormate absoluteString] hasSuffix:@"PNG"] || [[imageFormate absoluteString] hasSuffix:@"png"]){ 1202 //NSLog(@"imageFormate = PNG"); 1203 imageName = [NSString stringWithFormat:@"%@%d.PNG",date,i]; 1204 } 1205 else if([[imageFormate absoluteString] hasSuffix:@"GIF"] || [[imageFormate absoluteString] hasSuffix:@"gif"]){ 1206 //NSLog(@"imageFormate = GIF"); 1207 imageName = [NSString stringWithFormat:@"%@%d.GIF",date,i]; 1208 } 1209 else if([[imageFormate absoluteString] hasSuffix:@"BMP"] || [[imageFormate absoluteString] hasSuffix:@"bmp"]){ 1210 //NSLog(@"imageFormate = BMP"); 1211 imageName = [NSString stringWithFormat:@"%@%d.BMP",date,i]; 1212 } 1213 else if([[imageFormate absoluteString] hasSuffix:@"TIF"] || [[imageFormate absoluteString] hasSuffix:@"tif"]){ 1214 //NSLog(@"imageFormate = BMP"); 1215 imageName = [NSString stringWithFormat:@"%@%d.TIF",date,i]; 1216 } 1217 [viewController saveImage:image WithName:imageName]; 1218 } 1219 } 1220 1221 } 1222 else if([pickView isKindOfClass:[UIImagePickerController class]])//说明是用了视频拾取器 1223 { 1224 NSLog(@"info = %@",info); 1225 1226 if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeMovie]) 1227 { 1228 NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; 1229 NSData *fileData = [NSData dataWithContentsOfFile:videoPath]; 1230 NSLog(@"The video file length = %d", [fileData length]); 1231 1232 NSArray *pathArray = [videoPath componentsSeparatedByString:@"//"]; 1233 NSString *tmpFileName = pathArray[[pathArray count] -1]; 1234 NSArray *fileNameArray = [tmpFileName componentsSeparatedByString:@"."]; 1235 NSString *videoFileName = [[fileNameArray[1] stringByAppendingString:@"."] stringByAppendingString:fileNameArray[[fileNameArray count] - 1]]; 1236 1237 NSFileManager *fileManager = [NSFileManager defaultManager]; 1238 1239 NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 1240 NSString * documentsDirectory = [paths objectAtIndex:0]; 1241 NSString * fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"Sent"]; 1242 1243 BOOL isDir = FALSE; 1244 BOOL isDirExist = [fileManager fileExistsAtPath:fullPathToFile isDirectory:&isDir]; 1245 if(!(isDirExist && isDir)) 1246 { 1247 BOOL bCreateDir = [fileManager createDirectoryAtPath:fullPathToFile withIntermediateDirectories:YES attributes:nil error:nil]; 1248 if(!bCreateDir){ 1249 NSLog(@"Create Audio Directory Failed."); 1250 return; 1251 } 1252 NSLog(@"%@",fullPathToFile); 1253 1254 NSString *videoFilePath = [fullPathToFile stringByAppendingPathComponent:videoFileName]; 1255 [fileData writeToFile:videoFilePath atomically:YES]; 1256 [viewController.imageUrls addObject:videoFilePath]; 1257 }else{ 1258 NSString *videoFilePath = [fullPathToFile stringByAppendingPathComponent:videoFileName]; 1259 [fileData writeToFile:videoFilePath atomically:YES]; 1260 [viewController.imageUrls addObject:videoFilePath]; 1261 } 1262 } 1263#if !defined (__GENIE_IPHONE__) 1264 if(popoverController != nil) 1265 { 1266 [popoverController dismissPopoverAnimated:YES]; 1267 } 1268#endif 1269 } 1270 1271 [picker dismissModalViewControllerAnimated:YES]; 1272 1273// if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeImage]) 1274// { 1275// UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage]; 1276// NSData *fileData = UIImageJPEGRepresentation(img, 1.0); 1277// } 1278// else if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeMovie]) 1279// { 1280// NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; 1281// NSData *fileData = [NSData dataWithContentsOfFile:videoPath]; 1282// NSLog(@"The video file length = %d", [fileData length]); 1283// } 1284 1285 NSDictionary *dic = [PlistManipulate getDeviceMessage]; 1286 NSString *name = [[UIDevice currentDevice] name]; 1287 NSString *ip = [NSString stringWithString:[dic objectForKey:@"ipAddr"]]; 1288 NSLog(@"The dest ip to send file address = %@",ip); 1289 viewController.sendDeviceName = name; 1290 viewController.receiveDeviceName = [NSString stringWithString:[dic objectForKey:@"serviceName"]]; 1291 viewController.sendIp = ip; 1292 //设置为1 为发送标记 1293 viewController.fileFlag = [NSString stringWithFormat:@"1"]; 1294 //发送文件 1295 [self.navigationController pushViewController:viewController animated:YES]; 1296 //hi.tan 1297 1298} 1299 1300- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 1301{ 1302 [picker dismissModalViewControllerAnimated:YES]; 1303} 1304/* 1305#pragma mark - QBImagePickerControllerDelegate 1306// add by hi.tan: 多个图片文件拾取器 1307- (void)imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingMediaWithInfo:(id)info 1308{ 1309 NSLog(@"info:%@",info); 1310 // hi.tan 1311 1312 [imagePickerController dismissModalViewControllerAnimated:YES]; 1313 // _myFileTransfer = [[FileTransferViewController alloc] init]; 1314 //add by hi.tan 1315 FileTransferViewController *viewController = [FileTransferViewController SharedFileTransfer]; 1316 //截取文件名 1317 // self.imageName = @"11111";//[self setPhotoName:imageButton.imageURL]; 1318 //创建发送文件目录,并将图片移动到改目录 1319 NSString* date; 1320 NSDateFormatter* formatter = [[NSDateFormatter alloc]init]; 1321 //hi.tan edited:修改传输文件的名称 1322 //[formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"]; 1323 [formatter setDateFormat:@"YYYYMMddhhmmss"]; 1324 date = [formatter stringFromDate:[NSDate date]]; 1325 [formatter release]; //hi.tan for mem leak 1326 1327 int totalPicked = [info count]; 1328 int i = 0; 1329 1330 [viewController.imageUrls removeAllObjects]; 1331 1332 for(i = 0; i<totalPicked;i++) 1333 { 1334 NSString *mediaType = [info[i] objectForKey:UIImagePickerControllerMediaType]; //ALAssetTypePhoto ALAssetTypeVideo 1335 1336 if ([mediaType isEqualToString:@"ALAssetTypePhoto"]){ 1337 // UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 1338 UIImage *image = [info[i] objectForKey:@"UIImagePickerControllerOriginalImage"]; 1339 NSLog(@"found an image"); 1340 1341 NSURL *imageFormate = [info[i] objectForKey:@"UIImagePickerControllerReferenceURL"]; 1342 1343 NSData *webData = [NSData dataWithContentsOfURL:imageFormate]; 1344 1345 NSString *imageName = nil; 1346 1347 if([[imageFormate absoluteString] hasSuffix:@"JPG"] || [[imageFormate absoluteString] hasSuffix:@"jpg"]){ 1348 //NSLog(@"imageFormate = JPG"); 1349 imageName = [NSString stringWithFormat:@"Image%@%d.JPG",date,i]; 1350 } 1351 else if([[imageFormate absoluteString] hasSuffix:@"PNG"] || [[imageFormate absoluteString] hasSuffix:@"png"]){ 1352 //NSLog(@"imageFormate = PNG"); 1353 imageName = [NSString stringWithFormat:@"Image%@%d.PNG",date,i]; 1354 } 1355 else if([[imageFormate absoluteString] hasSuffix:@"GIF"] || [[imageFormate absoluteString] hasSuffix:@"gif"]){ 1356 //NSLog(@"imageFormate = GIF"); 1357 imageName = [NSString stringWithFormat:@"Image%@%d.GIF",date,i]; 1358 } 1359 else if([[imageFormate absoluteString] hasSuffix:@"BMP"] || [[imageFormate absoluteString] hasSuffix:@"bmp"]){ 1360 //NSLog(@"imageFormate = BMP"); 1361 imageName = [NSString stringWithFormat:@"Image%@%d.BMP",date,i]; 1362 } 1363 else if([[imageFormate absoluteString] hasSuffix:@"TIF"] || [[imageFormate absoluteString] hasSuffix:@"tif"]){ 1364 //NSLog(@"imageFormate = BMP"); 1365 imageName = [NSString stringWithFormat:@"Image%@%d.TIF",date,i]; 1366 } 1367 [viewController saveImage:image WithName:imageName]; 1368 //[UIImageJPEGRepresentation(image, 1.0f) writeToFile:[self findUniqueSavePath] atomically:YES]; 1369 //SETIMAGE(image); 1370 //CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]); 1371 } 1372 else if ([mediaType isEqualToString:@"ALAssetTypeVideo"]){ 1373 1374 ALAssetsLibrary *lib; 1375 1376 AVAssetReaderAudioMixOutput *out; 1377 1378 //NSURL *videoURL = [info[i] objectForKey:UIImagePickerControllerMediaURL]; 1379 NSURL *videoURL = [info[i] objectForKey:UIImagePickerControllerMediaURL]; 1380 1381 NSInputStream *input = [NSInputStream inputStreamWithURL:videoURL]; 1382 1383 //AVURLAsset *asset = [[AVURLAsset alloc] initWithURL: videoURL options:nil]; 1384 1385 //NSString* path = [videoURL path]; 1386 //UISaveVideoAtPathToSavedPhotosAlbum(path,self, @selector(video:didFinishSavingWithError:contextInfo:),nil); 1387 NSLog(@"found a video: videoURL = %@",videoURL); 1388 NSData *webData = [NSData dataWithContentsOfURL:videoURL]; 1389 //NSData *webData = [NSData dataWithContentsOfFile:path]; 1390 1391 NSString *vedioName = nil; 1392 if([[videoURL absoluteString] hasSuffix:@"MOV"] || [[videoURL absoluteString] hasSuffix:@"mov"]){ // 扩展对视频文件格式的支持 1393 //NSLog(@"imageFormate = BMP"); 1394 vedioName = [NSString stringWithFormat:@"%@%d.MOV",date,i]; 1395 } 1396 else if([[videoURL absoluteString] hasSuffix:@"MP4"] || [[videoURL absoluteString] hasSuffix:@"mp4"]){ // 扩展对视频文件格式的支持 1397 //NSLog(@"imageFormate = BMP"); 1398 vedioName = [NSString stringWithFormat:@"%@%d.MP4",date,i]; 1399 } 1400 else if([[videoURL absoluteString] hasSuffix:@"AVI"] || [[videoURL absoluteString] hasSuffix:@"avi"]){ // 扩展对视频文件格式的支持 1401 //NSLog(@"imageFormate = BMP"); 1402 vedioName = [NSString stringWithFormat:@"%@%d.AVI",date,i]; 1403 } 1404 else if([[videoURL absoluteString] hasSuffix:@"3GP"] || [[videoURL absoluteString] hasSuffix:@"3gp"]){ // 扩展对视频文件格式的支持 1405 //NSLog(@"imageFormate = BMP"); 1406 vedioName = [NSString stringWithFormat:@"%@%d.3GP",date,i]; 1407 } 1408 else if([[videoURL absoluteString] hasSuffix:@"AVC"] || [[videoURL absoluteString] hasSuffix:@"avc"]){ // 扩展对视频文件格式的支持 1409 //NSLog(@"imageFormate = BMP"); 1410 vedioName = [NSString stringWithFormat:@"%@%d.AVC",date,i]; 1411 } 1412 else if([[videoURL absoluteString] hasSuffix:@"MPEG"] || [[videoURL absoluteString] hasSuffix:@"mpeg"]){ // 扩展对视频文件格式的支持 1413 //NSLog(@"imageFormate = BMP"); 1414 vedioName = [NSString stringWithFormat:@"%@%d.MPEG",date,i]; 1415 } 1416 else if([[videoURL absoluteString] hasSuffix:@"FLV"] || [[videoURL absoluteString] hasSuffix:@"flv"]){ // 扩展对视频文件格式的支持 1417 //NSLog(@"imageFormate = BMP"); 1418 vedioName = [NSString stringWithFormat:@"%@%d.FLV",date,i]; 1419 } 1420 else if([[videoURL absoluteString] hasSuffix:@"IPOD"] || [[videoURL absoluteString] hasSuffix:@"ipod"]){ // 扩展对视频文件格式的支持 1421 //NSLog(@"imageFormate = BMP"); 1422 vedioName = [NSString stringWithFormat:@"%@%d.IPOD",date,i]; 1423 } 1424 else if([[videoURL absoluteString] hasSuffix:@"PSP"] || [[videoURL absoluteString] hasSuffix:@"psp"]){ // 扩展对视频文件格式的支持 1425 //NSLog(@"imageFormate = BMP"); 1426 vedioName = [NSString stringWithFormat:@"%@%d.PSP",date,i]; 1427 } 1428 else if([[videoURL absoluteString] hasSuffix:@"SWF"] || [[videoURL absoluteString] hasSuffix:@"swf"]){ // 扩展对视频文件格式的支持 1429 //NSLog(@"imageFormate = BMP"); 1430 vedioName = [NSString stringWithFormat:@"%@%d.SWF",date,i]; 1431 } 1432 else if([[videoURL absoluteString] hasSuffix:@"WMV"] || [[videoURL absoluteString] hasSuffix:@"wmv"]){ // 扩展对视频文件格式的支持 1433 //NSLog(@"imageFormate = BMP"); 1434 vedioName = [NSString stringWithFormat:@"%@%d.WMV",date,i]; 1435 } 1436 else if([[videoURL absoluteString] hasSuffix:@"MJPEG"] || [[videoURL absoluteString] hasSuffix:@"mjpeg"]){ // 扩展对视频文件格式的支持 1437 //NSLog(@"imageFormate = BMP"); 1438 vedioName = [NSString stringWithFormat:@"%@%d.MJPEG",date,i]; 1439 } 1440 else if([[videoURL absoluteString] hasSuffix:@"WMA"] || [[videoURL absoluteString] hasSuffix:@"wma"]){ // 扩展对视频文件格式的支持 1441 //NSLog(@"imageFormate = BMP"); 1442 vedioName = [NSString stringWithFormat:@"%@%d.WMA",date,i]; 1443 } 1444 else if([[videoURL absoluteString] hasSuffix:@"RM"] || [[videoURL absoluteString] hasSuffix:@"rm"]){ // 扩展对视频文件格式的支持 1445 //NSLog(@"imageFormate = BMP"); 1446 vedioName = [NSString stringWithFormat:@"%@%d.RM",date,i]; 1447 } 1448 else if([[videoURL absoluteString] hasSuffix:@"FLAC"] || [[videoURL absoluteString] hasSuffix:@"flac"]){ // 扩展对视频文件格式的支持 1449 //NSLog(@"imageFormate = BMP"); 1450 vedioName = [NSString stringWithFormat:@"%@%d.FLAC",date,i]; 1451 } 1452 else if([[videoURL absoluteString] hasSuffix:@"WAV"] || [[videoURL absoluteString] hasSuffix:@"wav"]){ // 扩展对视频文件格式的支持 1453 //NSLog(@"imageFormate = BMP"); 1454 vedioName = [NSString stringWithFormat:@"%@%d.WAV",date,i]; 1455 } 1456 1457 NSFileManager *fileManager = [NSFileManager defaultManager]; 1458 NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 1459 NSString * documentsDirectory = [paths objectAtIndex:0]; 1460 NSString * fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"Sent"]; 1461 1462 BOOL isDir = FALSE; 1463 BOOL isDirExist = [fileManager fileExistsAtPath:fullPathToFile isDirectory:&isDir]; 1464 if(!(isDirExist && isDir)) 1465 { 1466 BOOL bCreateDir = [fileManager createDirectoryAtPath:fullPathToFile withIntermediateDirectories:YES attributes:nil error:nil]; 1467 if(!bCreateDir) 1468 { 1469 NSLog(@"Create Audio Directory Failed."); 1470 return; 1471 } 1472 //NSLog(@"%@",fullPathToFile); 1473 NSString *videoFullPath = [fullPathToFile stringByAppendingPathComponent:vedioName]; 1474 //[webData writeToFile:videoFullPath atomically:YES]; 1475 UISaveVideoAtPathToSavedPhotosAlbum(videoFullPath,self, nil,nil); 1476 [viewController.imageUrls addObject:videoFullPath]; 1477 }else 1478 { 1479 NSString *videoFullPath = [fullPathToFile stringByAppendingPathComponent:vedioName]; 1480 //[webData writeToFile:videoFullPath atomically:YES]; 1481 UISaveVideoAtPathToSavedPhotosAlbum(videoFullPath,self, nil,nil); 1482 [viewController.imageUrls addObject:videoFullPath]; 1483 } 1484 1485 //[webData writeToFile:[self findUniqueMoviePath] atomically:YES]; 1486 //CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]); 1487 // NSLog(videoURL); 1488 } 1489 //[picker dismissModalViewControllerAnimated:YES]; 1490 } 1491 1492 //mov mp4 avi 3gp avc mpeg flv ipod psp swf wmv mjpeg wma rm flac wav mp3 1493 1494 NSDictionary *dic = [PlistManipulate getDeviceMessage]; 1495 NSString *name = [[UIDevice currentDevice] name]; 1496 NSString *ip = [NSString stringWithString:[dic objectForKey:@"ipAddr"]]; 1497 NSLog(@"The dest ip to send file address = %@",ip); 1498 viewController.sendDeviceName = name; 1499 viewController.receiveDeviceName = [NSString stringWithString:[dic objectForKey:@"serviceName"]]; 1500 viewController.sendIp = ip; 1501 //设置为1 为发送标记 1502 viewController.fileFlag = [NSString stringWithFormat:@"1"]; 1503 //发送文件 1504 [self.navigationController pushViewController:viewController animated:YES]; 1505 //hi.tan 1506} 1507 1508- (void)imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController 1509{ 1510 NSLog(@"Cancelled"); 1511 1512 [self dismissViewControllerAnimated:YES completion:NULL]; 1513} 1514 1515//hi.tan : 更新选择所有文件提示信息(图片和视频分开提示) 1516 1517- (NSString *)descriptionForSelectingAllAssets:(QBImagePickerController *)imagePickerController 1518{ 1519 NSString *str; 1520 if(imagePickerController.filterType == QBImagePickerFilterTypeAllPhotos){ 1521 str= Localization_FileTransfer_Select_All_Photos; 1522 } 1523 else{ 1524 str= Localization_FileTransfer_Select_All_Videos; 1525 } 1526 return str; 1527 //return @"选择所有照片"; 1528} 1529 1530- (NSString *)descriptionForDeselectingAllAssets:(QBImagePickerController *)imagePickerController 1531{ 1532 NSString *str; 1533 if(imagePickerController.filterType == QBImagePickerFilterTypeAllPhotos){ 1534 str = Localization_FileTransfer_Deselect_All_Photos; 1535 } 1536 else{ 1537 str = Localization_FileTransfer_Deselect_All_Videos; 1538 } 1539 return str; 1540 //return @"取消所有照片"; 1541} 1542 1543 1544- (NSString *)imagePickerController:(QBImagePickerController *)imagePickerController descriptionForNumberOfPhotos:(NSUInteger)numberOfPhotos 1545{ 1546 //return [NSString stringWithFormat:@"相片%d张", numberOfPhotos]; 1547 NSString *tmp = Localization_FileTransfer_All_Photos_Counter; 1548 NSString * str = [tmp stringByAppendingFormat:@": %d", numberOfPhotos]; 1549 return str; 1550 //return [str autorelease]; 1551} 1552 1553- (NSString *)imagePickerController:(QBImagePickerController *)imagePickerController descriptionForNumberOfVideos:(NSUInteger)numberOfVideos 1554{ 1555 //return [NSString stringWithFormat:@"视频%d集", numberOfVideos]; 1556 NSString *tmp = Localization_FileTransfer_All_Video_Counter; 1557 NSString * str = [tmp stringByAppendingFormat:@": %d", numberOfVideos]; 1558 return str; 1559 //return [str autorelease]; 1560} 1561 1562- (NSString *)imagePickerController:(QBImagePickerController *)imagePickerController descriptionForNumberOfPhotos:(NSUInteger)numberOfPhotos numberOfVideos:(NSUInteger)numberOfVideos 1563{ 1564 NSString *tmp1 = Localization_FileTransfer_All_Photos_Counter; 1565 NSString * str1 = [tmp1 stringByAppendingFormat:@": %d ", numberOfPhotos]; 1566 NSString * str2 = [str1 stringByAppendingFormat:Localization_FileTransfer_All_Photos_Counter]; 1567 NSString *str3 = [str2 stringByAppendingFormat:@": %d", numberOfVideos]; 1568 return str3; 1569 //return [NSString stringWithFormat:@"照片%d张、视频%d集", numberOfPhotos, numberOfVideos]; 1570} 1571// add by hi.tan: 多个图片文件拾取器 1572*/ 1573 1574 1575// If necessary, sets up state to show an activity indicator to let the user know that a resolve is occuring. 1576- (void)showWaiting:(NSTimer *)timer { 1577 if (timer == self.timer) { 1578 NSNetService* service = (NSNetService*)[self.timer userInfo]; 1579 if (self.currentResolve == service) { 1580 self.needsActivityIndicator = YES; 1581 1582 NSIndexPath* indexPath = [NSIndexPath indexPathForRow:[self.services indexOfObject:self.currentResolve] inSection:0]; 1583 if (indexPath.row != NSNotFound) { 1584 [m_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 1585 // Deselect the row since the activity indicator shows the user something is happening. 1586 [m_tableView deselectRowAtIndexPath:indexPath animated:YES]; 1587 } 1588 } 1589 } 1590} 1591 1592- (void)initialWaitOver:(NSTimer *)timer { 1593 self.initialWaitOver= YES; 1594 if (![self.services count]) 1595 [m_tableView reloadData]; 1596} 1597 1598- (void)sortAndUpdateUI { 1599 // Sort the services by name. 1600 [self.services sortUsingSelector:@selector(localizedCaseInsensitiveCompareByName:)]; 1601 [m_tableView reloadData]; 1602} 1603 1604 1605 1606/* 1607- (void)netServiceBrowser:(NSNetServiceBrowser *)netServiceBrowser didRemoveService:(NSNetService *)service moreComing:(BOOL)moreComing { 1608 1609 if (self.currentResolve && [service isEqual:self.currentResolve]) { 1610 [self stopCurrentResolve]; 1611 } 1612 1613 1614 [self.services removeObject:service]; 1615 1616 if (self.ownEntry == service) 1617 self.ownEntry = nil; 1618 if (!moreComing) { 1619 [self sortAndUpdateUI]; 1620 } 1621 1622 [[NSNotificationCenter defaultCenter] postNotificationName:@"BonjourChange" object:nil userInfo:nil]; 1623} 1624 1625- (void)netServiceBrowser:(NSNetServiceBrowser *)netServiceBrowser didFindService:(NSNetService *)service moreComing:(BOOL)moreComing { 1626 1627 // If a service came online, add it to the list and update the table view if no more events are queued. 1628 //hi.tan:设备名称作为服务名称的处理 1629 NSString *selfName = nil;//[[UIDevice currentDevice] name]; 1630 NSString *tmpname = [[[UIDevice currentDevice] name] stringByReplacingOccurrencesOfString:@"." withString:@"_"]; 1631 if([tmpname hasPrefix:@"_"]){ 1632 selfName = [tmpname substringFromIndex:1]; 1633 } 1634 else{ 1635 selfName = tmpname; 1636 } 1637 // end by hi.tan 1638 1639 NSString *servName = service.name; 1640 1641 NSLog(@"\nThe new income service = %@",servName); 1642 1643 if ([servName isEqual:selfName] || [servName hasPrefix:selfName]) //此处判断有待改进 1644 //if ([service.name isEqual:self.ownName]) 1645 self.ownEntry = service; 1646 else{ 1647 1648 if (![self.services containsObject:service] ) { 1649 // Add it to our list 1650 [self.services addObject:service]; 1651 } 1652// [self.services addObject:service]; 1653 1654 self.currentResolve = service; 1655 [self.currentResolve setDelegate:self]; 1656 1657 [self.currentResolve resolveWithTimeout:100]; 1658 1659 self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showWaiting:) userInfo:self.currentResolve repeats:NO]; 1660 1661 } 1662 1663 if (!moreComing) { 1664 [self sortAndUpdateUI]; 1665 } 1666 1667 [[NSNotificationCenter defaultCenter] postNotificationName:@"BonjourChange" object:nil userInfo:nil]; 1668} 1669 1670- (void)netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict { 1671 [self stopCurrentResolve]; 1672 [m_tableView reloadData]; 1673} 1674 1675//解析ip地址 1676-(NSMutableDictionary *) getIpAddr:(NSNetService *)service{ 1677 1678 NSString *name = nil; 1679 NSData *address = nil; 1680 struct sockaddr_in *socketAddress = nil; 1681 NSString *ipString = nil; 1682 int port; 1683 uint i; 1684 for (i = 0; i < [[service addresses] count]; i++) 1685 { 1686 name = [service name]; 1687 address = [[service addresses] objectAtIndex:i]; 1688 socketAddress = (struct sockaddr_in *) 1689 [address bytes]; 1690 if (![[NSString stringWithFormat: @"%s", 1691 inet_ntoa (socketAddress->sin_addr)] isEqual:@"0.0.0.0"]) { 1692 ipString = [NSString stringWithFormat: @"%s", 1693 inet_ntoa(socketAddress->sin_addr)]; 1694 } 1695 1696 port = socketAddress->sin_port; 1697 NSLog(@"Server found is %@ %d",ipString,port); 1698 } 1699 if(ipString == Nil) 1700 { 1701 //ipString = @"0.0.0.0"; 1702 if ([self.services containsObject:service]) 1703 { 1704 [self.services removeObject:service]; 1705 } 1706 return nil; 1707 } 1708 1709 NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:10]; //hi.tan : mem leak 1710 [dic setObject:[NSString stringWithFormat:@"%d",port] forKey:@"port"]; 1711 [dic setObject:ipString forKey:@"ipAddr"]; 1712 return dic; 1713} 1714 1715- (void)netServiceDidResolveAddress:(NSNetService *)service { 1716 1717 [service retain]; 1718 [self stopCurrentResolve]; 1719 [self tableViewData]; 1720 [self.delegate browserViewController:self didResolveInstance:service]; 1721 [service release]; 1722} 1723*/ 1724 1725 1726//解析ip地址后初始化tableview试图 1727-(void)tableViewData{ 1728 //设备列表 1729 if (m_tableView) { 1730 [m_tableView removeFromSuperview]; 1731 } 1732 1733 //edited by hi.tan: 屏幕旋转处理 1734 //m_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 30, 320, 340)]; 1735 m_tableView = [[UITableView alloc]initWithFrame:CGRectZero]; 1736 // add by hi.tan 1737 [self showViewWithOrientation:self.interfaceOrientation]; 1738 1739 m_tableView.backgroundColor = [UIColor clearColor]; 1740 1741 m_tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 1742 m_tableView.delegate = self; 1743 m_tableView.dataSource = self; 1744 [self.view addSubview:m_tableView]; 1745 1746} 1747 1748- (void)cancelAction { 1749 [self.delegate browserViewController:self didResolveInstance:nil]; 1750} 1751 1752- (void)dealloc { 1753 // Cleanup any running resolve and free memory 1754 [self stopCurrentResolve]; 1755 [self.currentResolve release]; //add by hi.tan for mem leak 1756 [self.services release]; 1757 //self.services = nil; 1758 [self.netServiceBrowser stop]; 1759 self.netServiceBrowser = nil; 1760 [_searchingForServicesString release]; 1761 [_ownName release]; 1762 [_ownEntry release]; 1763 1764 [m_tableView release]; 1765 [m_toolView release]; 1766 [m_imageView release]; 1767 [m_hosBtn release]; 1768 // hi.tan add: 清理内存 1769 [m_wifiView release]; 1770 [m_wifilab release]; 1771 [m_hisLab release]; 1772 [_currentResolve release]; 1773 [_timer release]; 1774 //end hi.tan 1775 [m_alert release]; 1776#if !defined (__GENIE_IPHONE__) 1777 [popoverController release]; 1778#endif 1779 1780 //hi.tan: 下拉刷新 1781 _refreshHeaderView = nil; 1782 //hi.tan: 下拉刷新 1783 [super dealloc]; 1784} 1785 1786 1787//历史纪录跳转页面 1788-(void)showHistoryView{ 1789 HistoryViewController *history = [[HistoryViewController alloc]init]; 1790 [self.navigationController pushViewController:history animated:YES]; 1791 [history release]; 1792} 1793//点击图片,连续播放图片动画 1794-(void)onClickImage{ 1795 //重新加在数据 1796 UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 48, 48)]; 1797 imageView.animationImages = [NSArray arrayWithObjects: 1798 [UIImage imageNamed:@"one.png"], 1799 [UIImage imageNamed:@"two.png"], 1800 [UIImage imageNamed:@"three.png"], 1801 [UIImage imageNamed:@"four.png"], 1802 [UIImage imageNamed:@"five.png"], 1803 nil]; 1804 //动画间隔事件 1805 [imageView setAnimationDuration:1.0f]; 1806 //动画连播次数 1807 [imageView setAnimationRepeatCount:4]; 1808 //开始动画 1809 [imageView startAnimating]; 1810 [m_toolView addSubview:imageView]; 1811 [imageView release]; 1812 1813 UIImageView *imageArr = [[UIImageView alloc] initWithFrame:CGRectMake(55, 0, 220, 50)]; 1814 imageArr.animationImages = [NSArray arrayWithObjects: 1815 [UIImage imageNamed:@"1.png"], 1816 [UIImage imageNamed:@"2.png"], 1817 [UIImage imageNamed:@"3.png"], 1818 [UIImage imageNamed:@"4.png"], 1819 [UIImage imageNamed:@"5.png"], 1820 [UIImage imageNamed:@"6.png"], 1821 [UIImage imageNamed:@"7.png"], 1822 [UIImage imageNamed:@"8.png"], 1823 [UIImage imageNamed:@"9.png"], 1824 nil]; 1825 [imageArr setAnimationDuration:1.0f]; 1826 [imageArr setAnimationRepeatCount:3]; 1827 [imageArr startAnimating]; 1828 [imageArr setAlpha:0.7]; 1829 [m_toolView addSubview:imageArr]; 1830 [imageArr release]; 1831 1832 //当按刷新或搜索新设备的时候,只让DLNA去发现和搜索,不让bonjour重新搜索了,bonjour服务只最开始搜索一次,以后发现有新设备就添加,发现服务消失就删除的功能 1833 //[[BonjourServiceResolving GetBonjourResolvInstance] searchForServicesOfType:@"_ros-master._tcp" inDomain:@"local"]; 1834 //上面这行代码在添加DLNA探测对方是否在线的功能近来后,不需要了,主要靠bonjour服务和DLNA来添加和删除设备 1835 //DLNADelegation::GetInstance()->refreshDevices((deejay::DLNACore::FlushMode)0);//该函数会将dlna底层的设备列表给清空 1836 DLNADelegation::GetInstance()->searchDevices(); 1837 // 发送一个搜索的广播消息出去,搜索设备 1838 //NSLog(@"图片被点击!"); 1839 [m_tableView reloadData]; 1840} 1841 1842//获取本设备连接的wifi名字 1843-(NSString *)getwifiName{ 1844 NSString *wifiStr = nil; 1845 CFArrayRef arrayRef = CNCopySupportedInterfaces(); 1846 NSArray *interfaces = (NSArray *)arrayRef; 1847 if (interfaces) { 1848 for (NSString *interfaceName in interfaces) { 1849 CFDictionaryRef dictRef = CNCopyCurrentNetworkInfo((CFStringRef)interfaceName); 1850 if (dictRef != NULL) { 1851 NSDictionary *networkInfo = (NSDictionary *)dictRef; 1852 wifiStr = [NSString stringWithFormat:@"%@",[networkInfo objectForKey:@"SSID"]]; //hi.tan for mem leak 1853 CFRelease(dictRef); 1854 } 1855 } 1856 CFRelease(arrayRef); 1857 } 1858 if(wifiStr == nil) 1859 { 1860 wifiStr = [NSString stringWithFormat:Localization_Mobile_Device_WIFI_NotEnable]; //hi.tan : localization for mem leak 1861 } 1862 return wifiStr; 1863} 1864@end
0 0
- Demo
- demo
- demo
- demo
- demo
- demo
- DEMO
- Demo
- DEMO
- demo
- Demo
- demo
- demo
- Demo
- demo
- demo
- Demo
- DEMO
- Windows 下/bin/bash: line 0: fg: no job control一般解决方法
- 第一行代码-7.2 访问其他程序中的数据
- 单链表的建立、测长、打印、删除节点、插入节点、排序、逆置操作。
- chrome 插件工具精选
- android RecyclerView 设置设置选中的一行的内容
- demo
- Redis学习笔记(-)
- 关于java.lang.IllegalMonitorStateException
- linux实战(八)----定时运行----实例运用
- 搭建Git服务器
- 根据C语言改写的java实现的,判定九宫格是否合法。记录
- 【CSS3】text-overflow 与 word-wrap
- Linux笔记(9)——挂载命令和用户登录查看命令
- [android]_[初级]_[android studio中使用单元测试]