ios 添加APP有视频播放功能,从WIFI和4g切换的处理
#pragma mark添加网络监听
+ (void)andNetSatusChangeNotify{
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
[[AFNetworkReachabilityManager sharedManager] FNK_addObserverBlockForKeyPath:@"networkReachabilityStatus" block:^(id _Nonnull obj, id _Nonnull oldVal, id _Nonnull newVal) {
if([oldValisEqual:newVal] && [newValintegerValue] ==2) {
FNKLog(@"连上无线网了");
}elseif(![oldValisEqual:newVal]&&([oldValintegerValue] ==2)&&([newValintegerValue] ==0)){
FNKLog(@"从无线网到断网");
}elseif(![oldValisEqual:newVal]&&([oldValintegerValue] ==2)&&([newValintegerValue] ==1)){
if (FNeedWifiChangeTo4gNotify) {
[self FNK_postNotificationWithName:FNKTools_Notify_WifiTo4g userInfo:@{}];
}
FNKLog(@"从无线网到4g");
}elseif(![oldValisEqual:newVal]&&([oldValintegerValue] ==1)&&([newValintegerValue] ==2)){
if (FNeed4GChangeToWifiNotify) {
[self FNK_postNotificationWithName:FNKTools_Notify_4gToWifi userInfo:@{}];
}
FNKLog(@"从4g网到无线");
}elseif(![oldValisEqual:newVal]&&([oldValintegerValue] ==1)&&([newValintegerValue] ==0)){
FNKLog(@"从4g网到断网");
}elseif(![oldValisEqual:newVal]&&([oldValintegerValue] ==1)&&([newValintegerValue] == -1)){
FNKLog(@"从4g网到未知网络");
}elseif(![oldValisEqual:newVal]&&([oldValintegerValue] ==2)&&([newValintegerValue] == -1)){
FNKLog(@"从WIFI网到未知网络");
}
[FNKNetTools shareNetStatus].lastNetStatus = (NSString*)newVal;
}];
}
AVPlayer播放视频链接修改请求头
由于公司做视频原创网站, 盗链现象特别严重, 每个月公司都要损失很多钱, 老板就火了, 做防盗链, 请求头认证客户端, 然后我就一脸懵逼啊, 国内百度, 国外谷歌啊, AVFoundation中的几个类头文件都翻遍了, 是在实找不到怎么修改请求头信息啊
后面虽然解决了, 还是写篇文章, 方便下后面的开发者吧
NSMutableDictionary * headers = [NSMutableDictionary dictionary];
[headers setObject:@"YourHeader"forKey:@"User-Agent"];
self.urlAsset = [AVURLAsset URLAssetWithURL:self.videoURL options:@{@"AVURLAssetHTTPHeaderFieldsKey" : headers}];// 初始化playerItemself.playerItem = [AVPlayerItem playerItemWithAsset:self.urlAsset];
self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
代码块