我正在创建一个必须显示CFUserNotificationDisplayAlert的应用,即使iPhone屏幕已锁定,目前我正在使用此代码
CFOptionFlags responseFlags = 0;
CFUserNotificationDisplayAlert(20.0, 3, NULL, NULL, NULL, CFSTR("Hello"), CFSTR("Hello World"), CFSTR("OK"), NULL, NULL, &responseFlags);
这在主屏幕上效果很好,但如果屏幕被锁定则不会弹出。还有什么我需要添加它才能使它出现在锁定屏幕上吗?
答案 0 :(得分:4)
您需要使用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);
...
有关iPhoneOS≤3.1的所有对话框描述键,请参阅http://iphonedevwiki.net/index.php/CFUserNotification。
(请注意,虽然它会显示在锁定屏幕上,但手机不会自动唤醒。)
答案 1 :(得分:2)
CFUserNotification
。 Push Notifications是iPhone的等价物。