nsnotification

iOS - NSNotificationCenter memory leak

余生颓废 提交于 2019-12-06 13:26:35
Instruments reports this a memory leak (98.6%, whatever that means): [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationSomeNotification object:self]; "self" is a subclass of UIImageView. Is including "self" in the notification causing a memory leak? If so, how do you resolve it? Better check your notification observer. The cause of memory leak might be there. Memory leaks are almost always it is not safe. Check again are there leakage accurately!? You can do this by using deleaker. 来源: https://stackoverflow.com/questions/4002080/ios-nsnotificationcenter-memory-leak

Get Notification of task progress from NSTask

亡梦爱人 提交于 2019-12-06 11:52:52
问题 Any body have idea about getting notification from NSTask while NSTask is executed. I am unzipping a zip file using NSTask and need to show the unzip data progress in a NSProgressBar. I don't found any idea for doing such task.So that i show the value in progress bar. Need help for doing this task. Thanks in advance. 回答1: Use NSFileHandleReadCompletionNotification , NSTaskDidTerminateNotification notifications. task=[[NSTask alloc] init]; [task setLaunchPath:Path]; NSPipe *outputpipe=[[NSPipe

UIWebView and Swift: Detect when a video starts playing

心已入冬 提交于 2019-12-06 09:56:49
问题 In Objective-C, I subscribed to the UIWindowDidBecomeVisibleNotification to know if some view gets above my current view controller, using: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoStartedPlaying:) name:UIWindowDidBecomeVisibleNotification object:nil]; So far, so good. Then, in the notification, I could check if the object is not of certain classes (like _UIAlertControllerShimPresenterWindow -alert views- or UITextEffectsWindow -native sharing view-). In

UIProgressView progress update very slow within AlamoFire (async) call

不问归期 提交于 2019-12-06 09:25:50
问题 Inside an AlamoFire get request I'm trying to update my progress bar. Like so: alamofireManager.request(.GET, urlPath, parameters: params).responseJSON{(request,response,JSON,error) in ...<code here>... dispatch_async(dispatch_get_main_queue(), { NSNotificationCenter.defaultCenter().postNotificationName(LoginVCHideSpinnerAndShowProgressBarName as String, object: self) }) ...<more code here>... } For some reasons this takes a few seconds to execute and if I use dispatch_sync instead the app

iOS - NSNotificationCenter multiple UIKeyboard notification

随声附和 提交于 2019-12-06 07:38:52
I have two view controllers let's call them A and B (1) in A I show a popOver containing a textField (2) in B there is an UITextView used for simple text editing I Have to manage the keyboard in A and in B to scroll the content hidden by the keyboard. I know how to reposition the content. What I need is a way to have different behavior on the same notifications types that in my are UIKeyboardWill(Show/Hide)Notification. What I've done so far : (1) I've added this code in each controller [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidAppear:) name

When responding to NSNotifications, what is the best practice for updating UIViews

自古美人都是妖i 提交于 2019-12-06 05:04:10
Since the NSNotification invokes its selector on a thread other than the main thread, I notice that any changes that you make to UIViews or other interface elements in response to that notification are often slow to take effect. This is most acute if the main thread is busy (as mine often is!). I can solve the problem by calling "performSelectorOnMainThread:". Is this really the best practice? - (void) gotMovieSaveFinishNotication: (NSNotification *) not { NSURL *exportMovieURL = (NSURL *) [not object]; //saving the composed video to the photos album ALAssetsLibrary* library = [[

How to migrate NSWorkspace notifications to Swift 4?

半世苍凉 提交于 2019-12-06 04:07:48
In Swift 3 I registered for sleep and wake notifications with this code: let notificationCenter = NSWorkspace.shared.notificationCenter notificationCenter.addObserver(self, selector: #selector(AppDelegate.sleepListener), name: NSNotification.Name.NSWorkspaceWillSleep, object: nil) notificationCenter.addObserver(self, selector: #selector(AppDelegate.wakeUpListener), name: NSNotification.Name.NSWorkspaceDidWake, object: nil) but after migrating to Swift 4, I get this error after applying the suggested fixes: Type 'NSNotification.Name' has no member 'NSWorkspace' How do I do this in Swift 4? To

Class method and instance method with the same name in Objective-C

十年热恋 提交于 2019-12-05 04:47:43
I have a solution for a notification problem which works well, but I'm afraid might be a bad idea. I have a notification that needs to be handled by each instance of a class and by the class itself. To handle this, I'm registering for a notification by both the class and instances of the class. Because it's the exact same notification, I've named the class and instance method the same. This follows the standard we've set for how notification handlers are named. Is this a bad idea? Is there some hidden got'ca that I'm missing. Will I be confusing the heck out of future developers? + (void

Is subclassing NSNotification the right route if I want to add typed properties?

泄露秘密 提交于 2019-12-05 01:33:56
I am trying to subclass NSNotification . Apple's docs for NSNotification state the following: NSNotification is a class cluster with no instance variables. As such, you must subclass NSNotification and override the primitive methods name , object , and userInfo . You can choose any designated initializer you like, but be sure that your initializer does not call NSNotification ’s implementation of init (via [super init] ). NSNotification is not meant to be instantiated directly, and its init method raises an exception. But this isn't clear to me. Should I create an initializer like this? -(id

Get Notification of task progress from NSTask

痴心易碎 提交于 2019-12-04 17:10:31
Any body have idea about getting notification from NSTask while NSTask is executed. I am unzipping a zip file using NSTask and need to show the unzip data progress in a NSProgressBar. I don't found any idea for doing such task.So that i show the value in progress bar. Need help for doing this task. Thanks in advance. Use NSFileHandleReadCompletionNotification , NSTaskDidTerminateNotification notifications. task=[[NSTask alloc] init]; [task setLaunchPath:Path]; NSPipe *outputpipe=[[NSPipe alloc]init]; NSPipe *errorpipe=[[NSPipe alloc]init]; NSFileHandle *output,*error; [task setArguments: