2011-02-03 3 views
2

iPhone의 일부 데이터를 암호화하는 도우미 메서드가 있습니다. 장치가 잠겨서 작업이 중단되면 방금 처리 한 파일을 삭제하려고합니다. 따라서 메서드가 호출되면 notifiaction listsner를 추가합니다.NSNotification을 수신 할 때 "관찰하지 말 것"경고 및 관찰 중지 방법?

두 가지 문제 : 1. 내가 청취자를 추가하는 데 사용하는 방법이 더 이상 사용되지 않는다는 경고가 나타납니다. 내가 어떻게 그럴 수 있니? 2. 처리가 완료되면 청취자를 없애고 싶습니다.하지만 어떻게해야합니까?

NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.ProtectedDataWillBecomeUnavailable, Handler); 

이 모든 관찰자에 적용, 예컨대 : 등등

UIKeyboard.WillHideNotification 
UIKeyboard.WillShowNotification 
UIDevice.OrientationDidChangeNotification 

과 :

private static foo(string sDestPathAndFile) 
{ 
    NSNotificationCenter.DefaultCenter.AddObserver ("UIApplicationProtectedDataWillBecomeUnavailable", 
    delegate(NSNotification oNotification) 
    { 
    Util.DeleteFile (sDestPathAndFile); 
    throw new InvalidOperationException ("Protected data became unavailable - device locked?"); 
    }); 

    // Do some processing here. 
    // ... 
    // Now get rid of the notification listener - but how? 
} 

답변

2

가되지 않는 경고를 제거하려면 다음을 사용해야합니다. 이것들은 NSNotificationCenter이 예상하는 적절한 NSString입니다. 내가 그렇게하지만 하나의 가능한 방법을 할 수있는 위치에 현재 아니에요으로 시달리지으로

, 나는이 먼저 손을 확인할 수없는 것은 :

사용 후, NSObject라는으로 addobserver 선언 을 제거하려면 :

NSObject obj = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.ProtectedDataWillBecomeUnavailable, handler); 

// do whatever you need to do 
// time to remove: 
NSNotificationCenter.DefaultCenter.RemoveObserver(obj); 
+0

감사합니다. 둘 다 작동했습니다. – Krumelur

관련 문제