views:

443

answers:

2

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  A: 

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

rpetrich
It is supported, i have this working as i described in my question but the problem is that its not appearing on the lock screen, however it does appear on the screen when iphone is not locked.
raziiq
Just because it works, doesn't mean it is supported. We developers on the jailbreak side of the fence use a *ton* of APIs that work (for some definition of work) that aren't supported by Apple. `CFUserNotification`s will *not* show on the lock screen; *push notifications* will.
rpetrich
Just browsing through your questions and it appears you are a jailbreak dev. If you need to show an alert on the SpringBoard (including the lockscreen), you can create an SBAlertItem subclass at runtime, customize it and activate it--it will show on the lock screen.
rpetrich
Ya you are right, i can use SBAlertItem subclass but still dont know how to instantiate classes on the runtime, if you have some source on how to do that, please post.
raziiq
MobileSubstrate has an example of creating a new class at runtime: http://svn.saurik.com/repos/menes/trunk/mobilesubstrate/MobileSafety.mm It even uses SBAlertItem :)
rpetrich
ahhh, again mobilesubstrate, tried getting hold of it quite sometimes but its really complex, tried ipodtouchfansforum tutorials also but to no avail. You know of any good tutorial on mobilesubstrate??
raziiq
`objc_allocateClassPair` to create a new class, then add methods using `class_addMethod`, then `objc_registerClassPair`, and finally you can send `alloc` to the class to create an new instance. After that, it's `SBAlertItem`-specific code.
rpetrich
Also, best place to get help on jailbreak-specific development is in #iphone on irc.saurik.com
rpetrich
+2  A: 

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

KennyTM