1:Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath: 上面是在IOS9以下一直報閃退;後來改成下麵解決: 2:CoreTelephony框架不是私有庫 私有框架的目錄為:/Applications/Xcode.a ...
1:Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath:
static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
上面是在IOS9以下一直報閃退;後來改成下麵解決:
static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell==nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; }
2:CoreTelephony框架不是私有庫
私有框架的目錄為:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/PrivateFrameworks/
可以看出CoreTelephony框架是在frameworks內而不是PrivateFrameworks,所以它是可以放心使用的。網上之所以有說CoreTelephony是私有庫,是因為在iOS6的時候是私有框架,後來蘋果又給公開了;
3:如何獲取電話狀態
a:首先要導入CoreTelephony框架:
@import CoreTelephony;
b:然後聲明一個CTCallCenter變數:
@interface ViewController () { CTCallCenter *center_; //為了避免形成retain cycle而聲明的一個變數,指向接收通話中心對象 } @end
然後監聽電話狀態:
- (void) aboutCall{ //獲取電話接入信息 callCenter.callEventHandler = ^(CTCall *call){ if ([call.callState isEqualToString:CTCallStateDisconnected]){ NSLog(@"Call has been disconnected"); }else if ([call.callState isEqualToString:CTCallStateConnected]){ NSLog(@"Call has just been connected"); }else if([call.callState isEqualToString:CTCallStateIncoming]){ NSLog(@"Call is incoming"); }else if ([call.callState isEqualToString:CTCallStateDialing]){ NSLog(@"call is dialing"); }else{ NSLog(@"Nothing is done"); } }; }
還可以獲取運營商信息:
- (void)getCarrierInfo{ // 獲取運營商信息 CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init]; CTCarrier *carrier = info.subscriberCellularProvider; NSLog(@"carrier:%@", [carrier description]); // 如果運營商變化將更新運營商輸出 info.subscriberCellularProviderDidUpdateNotifier = ^(CTCarrier *carrier) { NSLog(@"carrier:%@", [carrier description]); }; // 輸出手機的數據業務信息 NSLog(@"Radio Access Technology:%@", info.currentRadioAccessTechnology); }
當然這樣在真機進行測試,以下為輸出信息:
2015-12-29 16:34:14.525 RWBLEManagerDemo[1489:543655] carrier:CTCarrier (0x134e065c0) { Carrier name: [中國移動] Mobile Country Code: [460] Mobile Network Code:[07] ISO Country Code:[cn] Allows VOIP? [YES] } 2015-12-29 16:34:14.526 RWBLEManagerDemo[1489:543655] Radio Access Technology:CTRadioAccessTechnologyHSDPA