Some Guy
Some Guy

Reputation: 13578

How to get fake contacts in iOS Simulator?

How can I get fake contacts in iOS Simulator? Is there a shell script I can use or an editor for my contacts?

Edit: I use React Native so I can't just throw some Swift project in there - is there a command line tool or way to connect the iOS Simulator to my Contacts application on my Mac?

Upvotes: 22

Views: 15828

Answers (4)

sbauch
sbauch

Reputation: 830

if you're looking for a programmatic way to do this sort of thing, simctl is a nice tool -

/usr/bin/xcrun simctl addmedia booted ~/path/to/contact.vcf

NSHipster has a great writeup: https://nshipster.com/simctl/

One key thing I overlooked is that a simulator must be "booted" before you can interact with it programmatically.

I'm mostly doing this to be able to take screenshots with fastlane, and I run this bash script at the start of that lane.

It 1. lists all of the ios 13.4 devices 2. greps the UUIDs and 3. loops through each simulator to boot it, add a vcf, and shut it down

It takes a few minutes to run, but for me beats opening all of the simulators and dragging a vcf. I also clear the simulator data, as there's no de-duping here.

#!/bin/bash
xcrun simctl list devices 'iOS 13.4' \
| grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})" \
| while read line ; do 
  xcrun simctl boot $line
  /usr/bin/xcrun simctl addmedia booted PathTo.vcf
  xcrun simctl shutdown $line
done

Upvotes: 4

corysimmons
corysimmons

Reputation: 7685

Bit cleaner version of niftylettuce's answer, with Faker data, images, and extra data for evenly numbered contacts:

https://github.com/corysimmons/vcf-generator

Upvotes: 2

user3586413
user3586413

Reputation:

You can download this generated VCF file, and then drag/drop it to your Simulator to import (1000) fake contacts. I created this test data using the mock data generation website Mockaroo.

This was created using a small Node.js script that takes a CSV and converts it into one single VCF file - which you can then drag and drop to the iOS Simulator. This is the simplest way to import contacts, no code required or installation of apps needed off GitHub (as the other answers imply). This CSV parser assumes you have three columns at the top of the file (First Name, Last Name, and Phone Number. If you want to add more columns/variables for importing, simply modify your CSV and the parser below based off the vCard spec.

Save the below script as "mock.js" and run it with node mock (here's a GitHub gist of it). This assumes the script below, along with your CSV file (e.g. "MOCK_DATA.csv") is in the same directory. The output of running this script will be a file named "vcards.vcf".

const fs = require('fs');
const csv = fs.readFileSync('./MOCK_DATA.csv', 'utf8');
const records = csv.split('\n').slice(1);
const VCARDS = [];
records.forEach(function(record, i) {
  const data = record.split(',');
  const VCARD = [
    'BEGIN:VCARD',
    'VERSION:4.0',
    `N:${data[1]};${data[0]};;;`,
    `FN:${data[0]} ${data[1]}`,
    `TEL;type=HOME:${data[2]}`,
    'END:VCARD'
  ].join('\n');
  VCARDS.push(VCARD);
});
fs.writeFileSync(`./vcards.vcf`, VCARDS.join('\n'));

Upvotes: 43

Brian Trzupek
Brian Trzupek

Reputation: 5410

I just found this while looking to do the same. Here is what I ended up doing:

for i in {0..100}
do
    echo "BEGIN:VCARD\n
    VERSION:4.0\n
    PRODID:-//BBros.us llc//bvCard.com//EN\n
    N:User"$i";TEst;;;\n
    FN:TEst User"$i"\n
    EMAIL:test.user"$i"@domain.com\n
    ORG:Great Business\n
    END:VCARD" > "File$(printf "%03d" "$i").vcf"
done

In Terminal I changed to a test folder, and ran this script in there. It created the VCard files, and I then dragged them to a running simulator window and dropped them on the simulator. This caused the simulator to open Contacts and import them.

I hope this helps.

* UPDATE * So once I updated Xcode I can now only import a single contact at once, which is not ideal. This lead me to another solution:

https://github.com/cristianbica/CBSimulatorSeed-Swift

This is a quick app you can build & run in simulator to seed many contacts for you.

Upvotes: 0

Related Questions