ios - Screenshot showing up blank - Swift -


hi making game , have added share button game. want user able share message, url, , screenshot along side each other in 1 message.the sharing aspect of working fine , showing except screenshot showing blank. code using take screenshot:

   let layer = uiapplication.sharedapplication().keywindow!.layer     let scale = uiscreen.mainscreen().scale     uigraphicsbeginimagecontextwithoptions(layer.frame.size, false, scale);      layer.renderincontext(uigraphicsgetcurrentcontext())     let screenshot = uigraphicsgetimagefromcurrentimagecontext()     uigraphicsendimagecontext()      uiimagewritetosavedphotosalbum(screenshot, nil, nil, nil)      println("screenshot") 

please me resolve issue , please sure in swift language. using spritekit technology if makes difference. new coding please clear. thank much!

update: xcode 8.2.1 • swift 3.0.2

you need add import statement , extension game scene:

import uikit  

extension uiview {     var snapshot: uiimage? {         uigraphicsbeginimagecontextwithoptions(bounds.size, false, 0)         defer { uigraphicsendimagecontext() }         drawhierarchy(in: bounds, afterscreenupdates: true)         return uigraphicsgetimagefromcurrentimagecontext()     } } 

let myimage = view?.snapshot 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -