我的应用程序不断地将大量字节写入文件.如果我的代码块正在写出字节并且如果与驱动器或网络的连接丢失则获得IOException,我怎么知道它写了多少字节?
例如,我一次写2500个字节,如果发生IOException,是否意味着它没有写入文件,或者它会将部分字节写入文件?如果将部分字节写入文件,我怎么知道写了多少
仅供参考我正在使用
DataOutputStream
Run Code Online (Sandbox Code Playgroud)
写出文件.我的应用程序关闭时才刷新.
我使用Cocoapods来集成我的工作区.我在项目中使用了大约45个pod.我想归因于所有许可证标题,并且想知道有没有一种方法可以获取并连接所有标题或者我应该手动执行吗?
我需要在我的应用程序处于后台并通过重要位置更改唤醒时启动小型下载.但是这里的NSURLSessionConfiguration的Apples文档:
对于全权财产说以下内容:
传输大量数据时,建议您将此属性的值设置为YES.这样做可让系统在对设备更加优化的时间安排这些传输.例如,系统可能会延迟传输大文件,直到设备插入并通过Wi-Fi连接到网络.此属性的默认值为NO.
会话对象仅将此属性的值应用于应用程序在前台时启动的传输.对于在您的应用程序处于后台时启动的传输,系统始终自行开始传输 - 换句话说,系统假定此属性为YES并忽略您指定的任何值.
这似乎意味着如果在后台启动下载,操作系统始终可以自行决定是否以及何时继续下载.在完成这些任务之前,操作系统似乎总是在等待wifi连接.我的经验支持这个猜想.我发现当设备处于蜂窝状态时,我可以发送几个下载通知.他们仍然卡住了.当我将设备切换到wifi时,它们都会通过.
WTF?为什么Apple禁止配置此行为,尤其是因为它们具有NSURLSessionConfiguration对象上的必要属性(自行决定,allowCellularAccess).当然,当启动下载任务时,用户并不总是在WiFi中.我需要通过显着的位置更改来响应应用程序唤醒.我在后台会话上安排下载任务,并且在切换到WiFi之前永远不会在蜂窝网络上接收代表回调.那么这是否意味着我无法完成这些任务unil WiFi再次可用或我将应用程序带回前台?
你们有人为此解决了吗?
我已经想到了以下内容:
在位置更新后启动长时间运行的后台任务(旧样式)并使用defaultSessionConfiguration下载我的东西.任何经验,如果这可以工作?如果这不是我会使用NSURLConnection我认为(甚至更旧的风格).
background objective-c ios nsurlsession nsurlsessiondownloadtask
我的代码工作正常,直到iOS 8,kAudioFormatMPEG4AAC但现在它创建一个空文件.没有报告错误.当我把它更改为kAudioFormatLinearPCM它的工作原理.这是我的代码:
recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey,
[NSNumber numberWithInt: kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithInt:16], AVEncoderBitRateKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithFloat:32000.0], AVSampleRateKey,
nil];
Run Code Online (Sandbox Code Playgroud) while(!anotherThread.isDone());
Run Code Online (Sandbox Code Playgroud)
要么
while(!anotherThread.isDone())
Thread.sleep(5);
Run Code Online (Sandbox Code Playgroud) 如何以编程方式让活动进程在后台运行,iOS 的 CPU 和 RAM 使用情况?
我正在使用故事板构建一个 iOS 应用程序。我在我的应用程序中集成了谷歌地图并在点击时获取位置地址。
我想在滚动地图上的地图中心实现一个图钉将移动并提供与 Uber 或 Ola Cabs 应用程序中相同的位置地址。
有人可以帮助我如何实现这一点吗,我找到了一个教程(http://www.raywenderlich.com/81103/introduction-google-maps-ios-sdk-swift)但它很快,但我必须实现在目标 c.
这是我的代码:
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate{
// coordinate contains your coordinate :)
NSLog(@"did tap at coordinate: (%f, %f)", coordinate.latitude, coordinate.longitude);
NSString *address=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=AIzaSjhsdfg67tahdsg8981k8_5aJoZps",coordinate.latitude, coordinate.longitude];
NSURL *url=[NSURL URLWithString:address];
NSData* data = [NSData dataWithContentsOfURL:url];
if ((unsigned long)data.length > 3) {
// NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *file=@"/Data.json";
[data writeToFile:file atomically:YES];
NSArray *ys_avatars = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"array=%@",ys_avatars);
NSLog(@"status====%@",[ys_avatars valueForKey:@"status"]);
if([[ys_avatars valueForKey:@"status"] isEqual: @"OK"]){
NSArray *results=[ys_avatars valueForKey:@"results"]; …Run Code Online (Sandbox Code Playgroud) 当我的ViewController出现时,我需要得到一个空的文本字段.我试过这个:
override func viewWillAppear(animated: Bool) {
linkField.placeholder = "test"
linkField.text = ""
}
Run Code Online (Sandbox Code Playgroud)
但是当它出现时,键盘弹出,蓝色光标在textField中闪烁.我怎么能摆脱那些?
编辑:
我想我没有正确解释我的问题.我不需要得到一个空光标,我只需要隐藏它和键盘,直到用户触摸文本字段输入内容.
我试图改变使用CG绘制的矩形的宽度和颜色.在下面的函数中,我用不同的颜色屏蔽图像,但是如何更改宽度?
- (void)colorImage:(UIImage *)origImage withColor:(UIColor *)color withWidth:(float) width
{
UIImage *image = origImage;
NSLog(@"%f", width);
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, width);
CGContextClipToMask(context, rect, image.CGImage);
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *flippedImage = [UIImage imageWithCGImage:img.CGImage
scale:1.0 orientation: UIImageOrientationDownMirrored];
self.image = flippedImage;
}
Run Code Online (Sandbox Code Playgroud) ios ×7
objective-c ×4
java ×2
avfoundation ×1
background ×1
cocoapods ×1
file ×1
google-maps ×1
io ×1
ios8 ×1
iphone ×1
nsurlsession ×1
podspec ×1
swift ×1
system ×1