Arduino MKR1000 as Access Point
I found this reference for Wifi.beginAP() in the Wifi101 library, which I hope is the correct one - apologies if it's not.

It says that beginAP() returns either WL_AP_LISTENING or WL_CONNECT_FAILED, so checking for WL_CONNECTED is not sensible.

Try this:

if (WiFi.beginAP(ssid) != WL_AP_LISTENING) {
  Serial.println("Creating access point failed");
  while (true);
}