GCD – 用于更新UIImageView的主要vs后台线程

我是GCD的新手,并且正在放松自己。 背景:我正在使用ALAssetsLibrary为UIScrollView执行延迟加载例程。 当我的UIScrollView加载时,我使用aspectRatioThumbnails的aspectRatioThumbnails填充它,然后当用户滚动时,我调用下面的例程来加载当前正在显示的ALAsset的fullScreenImage 。 这似乎工作。 (如果有人有一个更好的延迟加载例程,请发表评论,我已经看了所有我能find的,加上WWDCvideo,但他们似乎处理更多的瓷砖或比我需要更复杂) 我的问题:我使用后台线程来处理加载fullScreenImage ,当完成后,我使用主线程将其应用到UIImageView。 我是否需要使用主线程? 我已经看到所有UIKit更新需要在主线程上发生,但我不确定是否适用于UIImageView。 我以为是这样,因为它是一个屏幕元素,但后来我意识到,我根本不知道。 – (void)loadFullSizeImageByIndex:(int)index { int arrayIndex = index; int tagNumber = index+1; ALAsset *asset = [self.assetsArray objectAtIndex:arrayIndex]; __weak typeof(self) weakSelf = self; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ UIImage *tmpImage = [[UIImage alloc] initWithCGImage:asset.defaultRepresentation.fullScreenImage]; if ([weakSelf.scrollView viewWithTag:tagNumber] != nil){ dispatch_async(dispatch_get_main_queue(), ^{ if ([weakSelf.scrollView viewWithTag:tagNumber]!= nil){ UIImageView * tmpImageView […]

iOS:强制退出应用程序是否禁用使用NSURLSession的后台上传?

问题在于NSURLSession和NSURLSessionUploadTask 。 我正在上传大文件到服务器,并注意到,当我强制退出应用程序整个背景上传只是停止。 但是,当应用程序通过Xcode /debugging器运行时上载启动时, 即使停止通过Xcode“停止”button运行应用程序,我的上传也可以完成。 我怀疑强制使用Xcode退出应用程序会模拟iOS系统命令而不是用户操作。 所以我的问题是,当用户强制退出应用程序时,iOS是否会立即取消NSURLSessionUploadTask ? 出于某种原因,我会至less期待一个错误callback的应用程序,但没有任何反应。

以编程方式更改UIPageViewController的页面不会更新UIPageControl

在我的自定义UIPageViewController类中: – (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { self.model = [[BSTCMWelcomingPageViewModel alloc] init]; self.dataSource = self.model; self.delegate = self; self.pageControl = [UIPageControl appearance]; self.pageControl.pageIndicatorTintColor = [UIColor lightGrayColor]; self.pageControl.currentPageIndicatorTintColor = [UIColor blackColor]; } return self; } 然后我编程设置当前的ViewController当一个button被击中: – (void)scrollToNext { UIViewController *current = self.viewControllers[0]; NSInteger currentIndex = [self.model indexForViewController:current]; UIViewController *nextController = […]

获取设备当前方向(应用程序扩展)

如何在应用程序扩展中获取设备当前的方向,我尝试了下面两种方法,但没有成功。 它总是返回UIDeviceOrientationUnknown [[UIDevice currentDevice] orientation] 它显示红色消息,“共享应用程序”不适用于iOS(应用程序扩展) [[UIApplication sharedApplication] statusBarOrientation]; 我也添加了一个观察者,但没有被调用。 [[NSNotificationCenter defaultCenter] addObserver:self.view selector:@selector(notification_OrientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; – (void)notification_OrientationWillChange:(NSNotification*)n { UIInterfaceOrientation orientation = (UIInterfaceOrientation)[[n.userInfo objectForKey:UIApplicationStatusBarOrientationUserInfoKey] intValue]; if (orientation == UIInterfaceOrientationLandscapeLeft) [self.textDocumentProxy insertText:@"Left"]; if (orientation == UIInterfaceOrientationLandscapeRight) [self.textDocumentProxy insertText:@"Right"]; } 那么现在怎样才能获得当前的设备定位。

Xcode 9 – 本地化问题警告故事板

我目前正在testingXcode 9 beta 3在写这篇文章的时候。 在查看故事板时,我收到了一个警告列表,指出在其他语言/地区,我的固定约束条件会造成问题。 应用程序相当复杂,许多视图正在遇到这些警告。 警告是: Certain autolayout constraint combinations may result in an appropriate layout in the current development language but will pose issues in other languages and regions. 我知道该应用程序将不会在任何其他语言使用很快。 有什么办法可以把这个警告关掉吗? 这听起来很愚蠢,但我不能忍受看到我所有的意见,黄色警告图标,并在顶部(110警告!)

隐藏导航栏

我有3个意见。 (比如说第一,第二,第三)。 我已经推出第二个视图(它有一个负载视图方法)。 在第二个视图中,我使用initWithFrame (从UIWebViewinheritance)创build了第三个视图。 在第二个视图中,我写了self.view = 3rd视图。 现在我想在第三个视图中隐藏第二个视图的导航栏(即,当用户触摸到第三个视图的屏幕,即UIWebView)。 我使用手势获得了触摸识别,但我无法隐藏导航栏。 第三个视图不支持self.navigationController 。 如果我在第三个创build第二个视图的对象,它不会隐藏导航栏。 有谁能够帮助我?

Swift框架不包括通用结构扩展的符号

我无法链接我的框架与利用该框架的代码。 具体而言,链接程序无法findgenerics结构的扩展符号。 这是可选的扩展之一: extension Optional { /// Unwrap the value returning 'defaultValue' if the value is currently nil func or(defaultValue: T) -> T { switch(self) { case .None: return defaultValue case .Some(let value): return value } } } 如果在应用程序的主要部分编译代码,此方法在游乐场或应用程序中效果很好。 但是,当我尝试将其编译为框架时,应用程序(甚至框架的testing)产生以下链接器错误: 架构i386的未定义符号:“__TFSq2orU__fGSqQ__FQQ”,引用来自:__TFC18SwiftPlusPlusTests27Optional_SwiftPlusPlusTests13testOrWithNilfS0_FT_T_可选+ SwiftPlusPlusTests.o 类似的方法,如下面的,链接罚款(注意,它不是一个通用的) extension String { /// Returns a string by repeating it 'times' times […]

UILocalNotification自定义声音不在iOS7中播放

我在应用程序中使用UILocalNotification 。 在应用程序中有两个有条件播放的声音 – 我已经为它们应用了适当的条件。 但是,当我安装应用程序并在iOS 7设备上运行它时,它会触发本地通知,但声音不在应用程序中播放。 下面给出的代码来设置通知: UILocalNotification *localNotification = [[UILocalNotification alloc] init]; if (localNotification == nil) return; localNotification.fireDate = [pickerView date]; localNotification.timeZone = [NSTimeZone defaultTimeZone]; if (alarm_number == 1) { localNotification.alertBody = [NSString stringWithFormat:@"First Alarm"]; } else { localNotification.alertBody = [NSString stringWithFormat:@"Second Alarm"]; } localNotification.alertAction =@"Ok"; NSString *message = [[NSString alloc]initWithString:@""]; if(alarm_number == […]

在应用程序内购买沙箱环境循环

我有我的生产应用程序中的应用程序内购买工作,我正在添加一个新的项目出售。 但是,我无法在沙盒环境中testing新的应用内购买。 我的购买显示正确。 恢复工作。 但是,如果我购买购买,那么我提示login。 我使用一个testing用户帐户login(我有4个工作大约一个月前,是活跃的)。 然后我被引导到AppStore,在那里我得到一个对话框popup说:[环境:沙箱]取消或继续。 当我继续时,系统提示我input苹果ID密码,然后按确定。 它说“加载…”几秒钟,然后popup窗口再次说[环境沙箱]取消/继续。 我经历了大约5次。 我已经尝试过以前用于testing的帐户,我已经创build了一个新用户,我尝试在两个月前都使用过的多个设备上进行testing。 我已重置我的设备。 与此同时,我已经能够testing出我的function,并且没问题 – 但是在发布更新之前我不能做我想要做的端到端的购买/testing。 有没有人见过类似的东西? 我正在寻找任何build议。 谢谢。

有没有办法从Apple Watch访问加速度计?

它看起来不像今天发布的WatchKit包含这样的API。