Edit: This answer doesn’t work for Xcode 10 and higher. See turkenh’s answer.
Solution
First of all, clean the project by holding Shift(⇧)+Command(⌘)+K or
Select Product > Clean
Then:
-
Go to Xcode Menu> Preferences
-
Select Accounts > Team > View Details
-
Select any Provisioning profile from the Provisioning Profiles list
-
Right-click > Select Show in Finder. Then you will see all lists of provisioning profiles
-
Select all provisioning lists from the folder and move them to the trash
-
Download All provisioning profiles by clicking Download All below Provisioning Profile lists.
Now, run again and it should work!