我已经写了一段时间的iPhone应用程序,将数据发送到服务器,接收数据(通过HTTP协议),而不用考虑太多.大多数情况下,我理论上熟悉流程,但我不太熟悉的部分是HTTP多部分请求.我知道它的基本结构,但它的核心是我.
似乎每当我发送不同于纯文本(如照片,音乐)的东西时,我都必须使用多部分请求.有人可以简单地向我解释为什么使用它以及它的优点是什么?
如果我使用它,为什么以这种方式发送照片更好?
我有两个类都在单独的头文件中定义.每个文件都有一个其他类的字段.现在我在每个文件的头文件中包含了其他文件的头文件,但是编译器正在生成错误.我错过了什么?
当我调用scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:主线程并将时间间隔设置为5秒时,下面的代码被执行,并且在5秒后调用定时器选择器.
但是如果我在某个后台线程中尝试相同,下面的代码scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:将不会被执行,它将等待定时器触发然后执行.当然,为了在后台线程中运行计时器,我首先得到了一个实例NSRunLoop并运行它.
有没有办法在后台线程中设置定时器并使其无阻塞,所以代码在它立即执行后?
CALayer *sublayer = [CALayer layer];
/*sublayer.backgroundColor = [UIColor blueColor].CGColor;
sublayer.shadowOffset = CGSizeMake(0, 3);
sublayer.shadowRadius = 5.0;
sublayer.shadowColor = [UIColor blackColor].CGColor;
sublayer.shadowOpacity = 0.8;*/
sublayer.frame = CGRectMake(30, 100, 256, 256);
sublayer.contents = (id)[[UIImage imageNamed:@"moon.png"] CGImage];
[self.view.layer addSublayer:sublayer];
//self.view.backgroundColor = [UIColor blackColor];
//add moon mask
UIGraphicsBeginImageContextWithOptions(CGSizeMake(400, 400), YES, 1);
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextClearRect(contextRef, CGRectMake(0, 0, 400, 400));
CGContextSetRGBFillColor(contextRef, 1, 1, 1, 0.8);
CGContextSetRGBStrokeColor(contextRef, 0, 0, 0, 0.5);
CGRect ellipse = CGRectMake(50, 50, 128, 128);
CGContextAddEllipseInRect(contextRef, ellipse);
CGContextFillEllipseInRect(contextRef, ellipse);
CALayer* sublayer2 = …Run Code Online (Sandbox Code Playgroud) 我一直在使用自定义覆盖UIImagePickerController控制器,一切正常.我已经添加了按钮,可以在前后摄像头之间切换 -
- (IBAction)changeCamera:(id)sender {
if (self.imagePicker.cameraDevice == UIImagePickerControllerCameraDeviceRear) {
self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
else {
self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,开关没有动画.我一直在使用建立在UIImagePicker之上的苹果相机应用程序,并且开关正在发生动画.我该怎么做呢?
我有一个消息服务,我用它来定期推送通知.例如,当一个用户发送消息时,另一个用户接收带有该消息的推送通知.我注意到如果手机是wifi和3g/4g,应用程序被杀死(屏幕被锁定),将收到通知.如果设备仅在wifi上并且应用程序被杀死(并且屏幕被锁定),则不会收到通知.
我的假设是,为了节省电池,设备在一段时间后断开与wifi的连接,这就是没有收到推送通知的原因.
但是当我使用VOIP推送通知时,情况就不同了.即使应用程序被杀死且设备处于wifi状态(并且屏幕已锁定),也会收到通知.那么这是什么意思?如果手机与wifi断开连接,手机如何接收此通知?
我在这里错过了什么?
我一直在使用UIPageController不同的控制器之间导航.现在我想在底部添加这些点,这样用户就可以看到他在哪个控制器上.这是通过UIPageControl.是否有简单的方法将这两者结合起来?
我一直试图从前置摄像头捕捉帧并将其呈现在视图上.这是我的代码
_session = [[AVCaptureSession alloc] init];
_session.sessionPreset = AVCaptureSessionPreset640x480;
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *deviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:device error:&error];
if (deviceInput) {
[_session addInput:deviceInput];
}
else {
DDLogInfo(@"Some wierd shit happened");
return;
}
// Session output
/*
AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[_session addOutput:output];
output.metadataObjectTypes = @[AVMetadataObjectTypeFace];
AVCaptureConnection *connection = [output connectionWithMediaType:AVMediaTypeMetadata];
connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
*/
// Session output
AVCaptureMovieFileOutput *videoOutput = [[AVCaptureMovieFileOutput alloc] init];
[_session addOutput:videoOutput];
AVCaptureConnection *connection = …Run Code Online (Sandbox Code Playgroud) 这就是我想要的 - 用户点击地图,我的代码被执行然后执行系统代码(如果用户点击了注释标注等等...).
我在地图视图中添加了简单的点按识别器:
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapViewTapped:)];
[self.mapView addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];
Run Code Online (Sandbox Code Playgroud)
在mapViewTapped里面我的代码被执行了.现在我想通知tap的系统代码(例如显示callout).我怎么做?如何通过我拦截的事件?
今天早上发生了一件有趣的事情,我将Xcode更新到版本9.3,之后,我无法归档我的项目.我可以构建它,在设备上运行它,但是当我尝试存档它时,我得到的是我缺少一些模块,比如Alamofire等...
我使用cocoapods作为依赖管理器.直到今天早上一切正常.有没有人有类似的问题?