Tag: callback

NSOperationQueue内部的NSOperation中的asynchronouscallback从来没有被调用过

我需要链接几个NSOperation s在一个NSOperationQueue做networking调用,然后等待所有完成。 我将所有的NSOperation添加到我的NSOperationQueue ,然后调用operationQueue.waitUntilAllOperationsAreFinished() 。 这是有效的,但是它会无限期地等待,因为NSOperations的callback将操作的状态设置为“已完成”,因此永远不会被调用。 我正在使用以下NSOperation子类: class ConcurrentOperation: NSOperation { enum State: String { case Ready, Executing, Finished private var keyPath: String { return "is" + self.rawValue } } var state: State = State.Ready { willSet (newValue) { self.willChangeValueForKey(newValue.keyPath) self.willChangeValueForKey(self.state.keyPath) } didSet { self.didChangeValueForKey(oldValue.keyPath) self.didChangeValueForKey(self.state.keyPath) } } } extension ConcurrentOperation { override var ready: […]

核心audio:文件播放呈现callback函数

我用kAudioUnitProperty_ScheduledFileIDs在我的应用程序中使用RemoteIOaudio单元进行audio播放。 audio文件是PCM格式。 我怎样才能实现这种情况下的渲染callback函数,所以我可以手动修改缓冲区样本? 这是我的代码: static AudioComponentInstance audioUnit; AudioComponentDescription desc; desc.componentType = kAudioUnitType_Output; desc.componentSubType = kAudioUnitSubType_RemoteIO; desc.componentManufacturer = kAudioUnitManufacturer_Apple; desc.componentFlags = 0; desc.componentFlagsMask = 0; AudioComponent comp = AudioComponentFindNext(NULL, &desc); CheckError(AudioComponentInstanceNew(comp, &audioUnit), "error AudioComponentInstanceNew"); NSURL *playerFile = [[NSBundle mainBundle] URLForResource:@"short" withExtension:@"wav"]; AudioFileID audioFileID; CheckError(AudioFileOpenURL((__bridge CFURLRef)playerFile, kAudioFileReadPermission, 0, &audioFileID), "error AudioFileOpenURL"); // Determine file properties UInt64 packetCount; […]

完成FetchRequest完成时的块/callback

我在名为ContentManager模型类中有一个FetchRequest 。 它获取了大量的数据,所以屏幕一直是空白的,直到完成。 在显示获取结果的ViewController中,我想显示一个加载指示器,所以我想在FetchRequest完成时得到一个callback,并将其传递给ViewController来停止加载指示器。 这可能吗? 以下是来自ContentManager类的FetchRequest : – (NSArray*)recipesForMagazine { NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Recipe" inManagedObjectContext:managedObjectContext]; [request setEntity:entity]; NSString* path = [[NSBundle mainBundle] pathForResource:@"magazine_recipe_guids" ofType:@"plist"]; NSArray* recipeGuids = [NSArray arrayWithContentsOfFile:path]; NSPredicate* predicate = [NSPredicate predicateWithFormat:@"guid IN %@",recipeGuids]; [request setPredicate:predicate]; NSSortDescriptor* sort = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]; [request setSortDescriptors:[NSArray […]

如何并行执行多个callback方法

我在集成Web服务时使用callback方法。 任何人都可以build议,我怎么可以并行使用多个callback方法, 我知道我们可以通过创build来集成多个Web服务 dispatch_group_t group = dispatch_group_create(); //block 1 dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{ [self getUserProfiles]; }); //block 2 dispatch_group_notify(group, dispatch_get_global_queue(0, 0), ^{ // block 2 will get notify, after block 1 complete his task. } 但是如何执行上面的,使用callback? 任何build议将不胜感激。

在FitBitlogin页面login后如何redirect到我的iOS应用程序?

我正在用Swift开发一个非常基础的iOS应用程序。 只是读取心率数据。 我正在使用SFSafariViewController。 众所周知,我首先需要在dev.fitbit.com上注册我的应用程序。 registry格需要input一个callbackURL。 成功login后,FitBit总是将我redirect到input的callbackURL。 我应该怎么做/代码/configuration成能够重新定向用户回到我的iOS应用程序login成功后?

从Core Audio Callback更新UI的最佳做法是什么?

我目前正在围绕Core Audio进行包装,并且遇到了如何更新GUI AudioQueueInputCallback的问题。 首先,我想用麦克风的电平表读数来更新标签。 在我的代码中,我将当前的电平表值存储在每个callback的结构中。 func MyAudioQueueInputCallback(inUserData: UnsafeMutablePointer<Void>, inAQ: AudioQueueRef, inBuffer: AudioQueueBufferRef, inStartTime: UnsafePointer<AudioTimeStamp>, var inNumberPacketDesc: UInt32, inPacketDesc: UnsafePointer<AudioStreamPacketDescription>){ var error: OSStatus if (inNumberPacketDesc > 0){ error = AudioFileWritePackets(MyRecorder.recordFile, false, inBuffer.memory.mAudioDataByteSize, inPacketDesc, MyRecorder.recordPacket, &inNumberPacketDesc, inBuffer.memory.mAudioData) checkError(error, operation: "AudioFileWritePackets Failed ") // Increment the packet index MyRecorder.recordPacket += Int64(inNumberPacketDesc) if (MyRecorder.running){ error = AudioQueueEnqueueBuffer(inAQ, inBuffer, inNumberPacketDesc, […]

从列表视图保存数据的正确方法是什么?

我有一个SearchPage组件执行一个查询,然后在列表视图中显示结果。 用户然后通过点击他们来select他们想要的结果。 这将它们保存到SearchResults组件的数组中。 如下面的代码所示,当返回结果时调用“displayWords”方法。 它推动堆栈上的新视图,SearchResults,将右边的button设置为“Save”,并附加一个要调用的函数来保存数据。 class SearchPage extends Component { 显示词(词){ this.props.navigator.push({ 标题:“结果”, 组件:SearchResults, rightButtonTitle:'保存', onRightButtonPress:()=> {this.props.navigator.pop(); this.props.save()}, passProps:{listing:words} }); this.setState({isLoading:false,message:''}); } 所以这里是一个问题,我如何从SearchResults组件中的数组中获取项目到callback中? 还是到SearchPage? 或者还有另一种模式,我应该遵循?

如何在iOS中创build应该由库调用的callBack

我正在开发一个使用以C-Language编写的PJSIP Library的VOIP_App,根据情况自动调用写在该库中的大部分方法。 有一个名为on_incoming_call方法自动调用,用户接收调用,我想添加一些用户交互来接收调用,我需要创build一些callBack,这个方法应该被调用,方法定义应该写在Objective-C 这里是代码片段: /* Callback called by the library upon receiving incoming call */ static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata) { pjsua_call_info ci; PJ_UNUSED_ARG(acc_id); PJ_UNUSED_ARG(rdata); pjsua_call_get_info(call_id, &ci); PJ_LOG(3,(THIS_FILE, "….\n\n\n Incoming call from %.*s!! \n\n\n", (int)ci.remote_info.slen, ci.remote_info.ptr)); /* Automatically answer incoming calls with 200/OK */ pjsua_call_answer(call_id, 200, NULL, NULL); }

观察asynchronous请求

我有三个独立的API调用。 当所有三个调用完成后,我将汇总数据并使用它来形成一个单独的模型对象。 我想我会用财产观察员来做到这一点,但我不知道它将如何实施。 任何帮助或指导将不胜感激。 我创build了一个模型对象来进行networking调用,将响应数据传递给一个转义闭包。 这是parsing数据的function: func loadLibrary() { // League Data Containers var names = Dictionary<Int, String>() // API Call 1 var titles = Dictionary<Int, String>() // Call 1 var masteryLevels = Dictionary<Int, Int>() // 2 var masteryPoints = Dictionary<Int, Int>() // 2 // Champion Data Containers var championRolesLibrary = Array<Dictionary<String,Array<Role>>>() // 3 var […]

在Swift 2中创buildASYNC任务

我想在地图上显示用户当前的位置,我知道这不是即时的任务。 我想在ASYNC任务中调用我的showCurrentLocation()函数。 我试图学习callback闭包,但我不明白如何创buildASYNC任务。 我知道这不是一个最好的问题模板为stackoverflow,但我不知道我怎么能不同地问。 感谢您的任何帮助。 有一个很好的编码。