在iPhone锁定屏幕上显示CFUserNotificationDisplayAlert [英] Display CFUserNotificationDisplayAlert on iPhone Lock Screen
问题描述
我正在创建一个必须显示CFUserNotificationDisplayAlert的应用,即使iPhone屏幕已锁定,目前我正在使用此代码
I m creating an app that has to display CFUserNotificationDisplayAlert even if iPhone Screen is Locked, currently i am using this code
CFOptionFlags responseFlags = 0;
CFUserNotificationDisplayAlert(20.0, 3, NULL, NULL, NULL, CFSTR("Hello"), CFSTR("Hello World"), CFSTR("OK"), NULL, NULL, &responseFlags);
这在主屏幕上效果很好,但如果屏幕被锁定则不会弹出。还有什么我必须添加到它以使它出现在锁定屏幕上吗?
This works great on Home Screen but doesnt pop up if the screen is locked. Is there anything else i have to add to it to make it appear on the Lock Screen as well?
推荐答案
你需要使用 kCFUserNotificationAlertTopMostKey
键。
extern CFStringRef kCFUserNotificationAlertTopMostKey;
CFStringRef keys[] = {
kCFUserNotificationAlertTopMostKey,
kCFUserNotificationAlertHeaderKey,
kCFUserNotificationAlertMessageKey
};
CFStringRef values[] = {
kCFBooleanTrue,
CFSTR("Title"),
CFSTR("Message")
};
CFDictionaryRef dict = CFDictionaryCreate(NULL, keys, values,
sizeof(keys)/sizeof(*keys),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
SInt32 err = 0;
CFUserNotificationRef notif = CFUserNotificationCreate(NULL,
0, kCFUserNotificationPlainAlertLevel, &err, dict);
CFRelease(dict);
...
参见 http://iphonedevwiki.net/index.php/CFUserNotification ,适用于iPhoneOS≤3.1的所有对话框描述键。
See http://iphonedevwiki.net/index.php/CFUserNotification for all dialog description keys for iPhone OS ≤ 3.1.
(请注意,虽然它会显示在锁定屏幕上,但手机不会自动唤醒。)
(Note that while it will show on the lock screen, the phone won't wake up by itself.)
这篇关于在iPhone锁定屏幕上显示CFUserNotificationDisplayAlert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!