Nanoporous polyelectrolyte membranes with hierarchical and unique pore architectures can be readily made via electrostatic complexation between imidazolium-based poly(ionic liquid)s and poly(acrylic acid) in a variety of morphologies. Coating the membrane onto the surface of an optical fiber resulted in a device with high pH-sensing performance in terms of the response rate and the sensitivity, due to the charge and porous nature of the membrane layer.