سؤال

قمت بإنشاء تطبيق بسيط لمعرفة كيفية استخدام NSWorkSpaceWillSleEpnotification و NSWorkSpacedidWakenotification.هدفي هو استدعاء طريقة عندما ينام الكمبيوتر ويصلح.سيتم تغيير التطبيق الذي أنشأته كل ملصق وفقا لذلك.بعد بناء التطبيق، أقوم بتشغيله من سطح المكتب الخاص بي.بعد إطلاق التطبيق، أضع الكمبيوتر للنوم.عندما يستيقظ الكمبيوتر على التسميات في التطبيق لا تتغير.أضفت أزرار iBaction إلى النافذة للتأكد من أن التسميات ستتغير.عندما يتم الضغط على الأزرار على التسميات التي تتغير بالفعل.لكنني أريد أن يحدث شيء من هذا القبيل تلقائيا عند النوم والاستيقاظ.ماذا أفعل الخطأ؟ giveacodicetagpre.

هل كانت مفيدة؟

المحلول

Instead of [[NSWorkspace sharedWorkspace] notificationCenter] try using [NSNotificationCenter defaultCenter]

like this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(makeSleep:) NSWorkspaceWillSleepNotification object:nil ];

and

[[NSNotificationCenter defaultCenter] addObserver:self @selector(makeWake:) NSWorkspaceDidWakeNotification object:nil ];

The above is incorrect, see https://developer.apple.com/library/mac/qa/qa1340/_index.html

Using [[NSWorkspace sharedWorkspace] notificationCenter] is necessary.

You should add observers upon - (void)awakeFromNib method.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top