If you're on iOS 11.4.1 or iOS 12 and go more than an hour without unlocking your iPhone, an "Unlock iPhone to Use Accessories" message will appear whenever you connect your iPhone to a computer or other device that tries to use the Lightning cable's data lines. This is to protect you, but it can be annoying if you have no reason to believe that law enforcement or criminals will have access to your iPhone.
The feature is an extension of one that Apple initially added in the 11.3 beta but didn't make its way to the public until iOS 11.4, where an iPhone locked for seven days would require to be unlocked before a computer or other accessory can access its data. This includes trusted devices, which otherwise needed no priming other than the initial process of trusting it once you first connect the two.
Apple added the feature to prevent organizations such as the FBI and local law enforcement, as well as hackers, from using brute-force tools like GrayKey and Cellebrite from accessing your data without your permission. If you're not worried about any future run-ins with the law or are a corporate employee at risk of being hacked, it's likely this extra security in iOS 11.4.1 and iOS 12 will just be irritating.
If you haven't unlocked your iPhone in over an hour, whenever you plug your iPhone into your computer to charge it, your iPhone will vibrate and bring up the "Unlock iPhone to Use Accessories." While this prevents any data-stealing efforts, it also disables charging capabilities. You can plug your iPhone into a wall outlet and charge no problem, but connecting to a computer will require that you unlock your iPhone, if presented with the message, before it can charge.
Obviously, if you plug it in real quick and don't notice the message, you may be left with a dead iPhone whenever you go to grab it next. To prevent this from happening, open up Settings, tap "Touch ID & Passcode" or "Face ID & Passcode," then enter in your passcode. From there, scroll down until you see a toggle that says "USB Accessories" and switch it on.
With this new security feature disabled in iOS 11.4.1 and iOS 12, your iPhone will likely revert to iOS 11.4's security settings, where it will need to be unlocked to transfer data or charge the device using a data accessory if it hasn't been unlocked in seven days.
Either way you choose to go with this setting, you should know that there are reports that the new protections by Apple are still capable of being brute-forced by hacking tools. So whether you have it set for one hour or seven days, there's still a chance someone can bypass your iPhone's security and gain access to your data.
Just updated your iPhone? See everything that's new with Apple's latest iOS update: