A stable porous metal-organic framework (MOF) containing methyl viologen cations exhibits reversible photochromic, thermochromic and fluorescence changes via host-guest interactions, and can be used for fast and selective detection of oxygen by naked eye recognition of color change within five seconds.