This already exists for calls on iOS. It is under Do not Disturb in settings. Allow calls from Everyone, Favourites or contacts.
* Always, no notification of calls or texts from people not in my contacts.
* Scheduled at night, when I'm asleep, no notification of calls or texts from anyone, unless they call twice in a row (emergency calls).
As far as I know, I can't set up Do Not Disturb to do this.
It’s twice. Under Settings → Do Not Disturb → Repeated Calls:
> A second call from the same person within three minutes will not be silenced.