glReadPixel works well when multi-sampling is not enabled. But when multisampling is enabled, it gives 0x502 opengl error and screen is not captured. After researching a little bit, it seems to be related to resolving multi-samples buffers - 'glResolveMultisampleFramebufferAPPLE'. But I could not get it to work inside 'takeAsCGImage' method as below