Why does my Macbook Air automatically shut down when i connect my iPhone to it? It doesn't happen every time. The last time I connected my iPhone to my MacBook Air was last week, and everything was fine.

Sometimes my MacBook Air shuts down when I connect my iPhone to it. What should I do about this?
The Macbook Air tries to supply a full charging current to the iPhone, but when the Air is running on battery and doesn't have a full charge, it loads the battery down enough for the Air to go into low power mode.

When you connect you iPhone, make sure you have a full battery on the Air, or are plugged in.  This will also happen less frequently if the iPhone battery is full, but the main issue is making sure the Air has enough power to give a full amp to the iPhone without shutting down.

This doesn't affect the larger notebooks as noticeably due to their larger battery packs, but as they age and when they have low charge you would see the same issue from them.