Wasted two or more days on it, tried everything, but found that the issue was only because I was running the app in the simulator. On a real device, it is working perfectly fine.