在iPhone锁定屏幕上显示CFUserNotificationDisplayAlert

时间:2010-02-04 12:35:19

标签: iphone xcode jailbreak

我正在创建一个必须显示CFUserNotificationDisplayAlert的应用,即使iPhone屏幕已锁定,目前我正在使用此代码

CFOptionFlags responseFlags = 0;
CFUserNotificationDisplayAlert(20.0, 3, NULL, NULL, NULL, CFSTR("Hello"), CFSTR("Hello World"), CFSTR("OK"), NULL, NULL, &responseFlags);

这在主屏幕上效果很好,但如果屏幕被锁定则不会弹出。还有什么我需要添加它才能使它出现在锁定屏幕上吗?

2 个答案:

答案 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)

iPhone OS不支持

CFUserNotificationPush Notifications是iPhone的等价物。