Friday 15 March 2013

objective c - How to use IOPMAssertionCreateWithName in swift -



objective c - How to use IOPMAssertionCreateWithName in swift -

i want app when user want sleep os x, , go on sleep. found way prevent scheme sleeping in oc, when utilize swift rewrite code, xcode can't recognize kiopmassertiontypenodisplaysleep parameter. how can utilize it?

iopmassertionid assertionid; ioreturn success = iopmassertioncreatewithname(kiopmassertiontypenodisplaysleep, kiopmassertionlevelon, reasonforactivity, &assertionid); if (success == kioreturnsuccess) { //add work need without // scheme sleeping here. success = iopmassertionrelease(assertionid); //the scheme able sleep again. }

kiopmassertiontypenodisplaysleep defined in iopmlib.h

/*! * @define kiopmassertiontypenodisplaysleep * @deprecated deprecated in 10.7. * @abstract please utilize assertion type <code>@link kiopmassertpreventuseridledisplaysleep@/link</code> instead. */ #define kiopmassertiontypenodisplaysleep cfstr("nodisplaysleepassertion")

and cfstr() definition not imported swift. workaround, can define constant as

let kiopmassertiontypenodisplaysleep = "nodisplaysleepassertion" cfstring

however, due deprecation notice, should use

let kiopmassertpreventuseridledisplaysleep = "preventuseridledisplaysleep" cfstring

instead:

var assertionid : iopmassertionid = iopmassertionid(0) allow success = iopmassertioncreatewithname(kiopmassertpreventuseridledisplaysleep, iopmassertionlevel(kiopmassertionlevelon), reasonforactivity, &assertionid) if success == kioreturnsuccess { // ... iopmassertionrelease(assertionid) }

objective-c cocoa swift

No comments:

Post a Comment