Display CFUserNotificationDisplayAlert on iPhone Lock Screen

青春壹個敷衍的年華 提交于 2019-12-17 18:51:14

问题


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?


回答1:


You need to use the kCFUserNotificationAlertTopMostKey key.

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);
...

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.)




回答2:


CFUserNotification is not supported on the iPhone OS. Push Notifications are the iPhone equivalent.



来源:https://stackoverflow.com/questions/2199642/display-cfusernotificationdisplayalert-on-iphone-lock-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!