IOS開發基礎知識--片段48,ios基礎知識--48
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