Disclaimer: I do not accept responsibility for any issues arising from scripts being run without adequate understanding. It is the user's responsibility to review and assess any code before execution. More information

Moving WhatsApp Contacts (not saved to iPhone Contacts) between phones.....

When moving to a new iPhone, most people assume that all their WhatsApp contacts will automatically transfer—but that isn’t always the case. If the “Sync to Contacts” option isn’t enabled, WhatsApp stores numbers only within the app and not in your phone’s address book.


Note : This guide requires the old and the new phones to be available - when you attempt to sign in on the new phone, it will sign you out on the old phone, If you need to switch back to the old phone to follow this Guide, you will need to be able to receive a SMS For verification to old phone.

This subtle detail can lead to missing names, unknown numbers in conversations, and a confusing start on your new phone—making it essential to understand how WhatsApp handles contact storage before performing a restore, but there is a extension that will help you where with the use of WhatsApp web.

Step 1: Create an iTunes Backup

Important: You must create a local iTunes backup (not iCloud). The backup must be encrypted to include WhatsApp data.

  1. Connect your iPhone to your computer
  2. Open iTunes (or Finder on macOS Catalina and later)
  3. Select your iPhone when it appears
  4. Under "Backups" section:
    • Choose "Back up to this computer" (not iCloud)
    •  Check "Encrypt iPhone backup" (CRUCIAL - WhatsApp data won't be included without this)
    • Set a password you'll remember
  5. Click "Back Up Now"
  6. Wait for the backup to complete (can take 10-30 minutes)

Step 2: Download Required Software

You'll need two free tools:

iPhone Backup Extractor (Free Version)

  • Download from: https://www.iphonebackupextractor.com/
  • The free version allows extracting 4 files at a time (sufficient for our needs)
  • Install and launch the application

DB Browser for SQLite (Free)

  • Download from: https://sqlitebrowser.org/
  • This will open and query the WhatsApp database
  • Install and keep ready for Step 4

Step 3: Extract WhatsApp Database from Backup

  1. Open iPhone Backup Extractor
  2. Select your backup from the list (it should auto-detect)
  3. Enter your backup password when prompted


  4. Click on "Expert Mode" or "App View" (depending on version)




  5. Navigate to:
    App Domain Groups → group.net.whatsapp.WhatsApp.shared
    
  6. Look for the file: ChatStorage.sqlite



  7. Select the file and click "Extract"
  8. Save it to your Desktop or another easy-to-find location

Step 4: Open Database in SQLite Browser

  1. Launch DB Browser for SQLite
  2. Click "Open Database"
  3. Navigate to and select the ChatStorage.sqlite file you extracted


  4. Click on the "Execute SQL" tab

Step 5: Run the Contact Extraction Query

Copy and paste this exact SQL query into the SQL window (shown in the empty green box above)

SELECT 
    ZPARTNERNAME as Name,
    CASE 
        WHEN ZCONTACTJID LIKE '44%' THEN 
            '+44 ' || SUBSTR(REPLACE(REPLACE(ZCONTACTJID, '@s.whatsapp.net', ''), '@whatsapp.net', ''), 3)
        WHEN ZCONTACTJID LIKE '1%' THEN 
            '+1 ' || SUBSTR(REPLACE(REPLACE(ZCONTACTJID, '@s.whatsapp.net', ''), '@whatsapp.net', ''), 2)
        ELSE 
            '+' || REPLACE(REPLACE(ZCONTACTJID, '@s.whatsapp.net', ''), '@whatsapp.net', '')
    END as PhoneNumber
FROM ZWACHATSESSION
WHERE ZCONTACTJID IS NOT NULL 
    AND ZCONTACTJID != ''
    AND ZCONTACTJID NOT LIKE '%@g.us'
    AND ZCONTACTJID NOT LIKE '%@status'
    AND ZCONTACTJID NOT LIKE '%broadcast%'
    AND (ZCONTACTJID LIKE '%@s.whatsapp.net' OR ZCONTACTJID LIKE '%@whatsapp.net')
    AND (ZGROUPINFO IS NULL OR ZGROUPINFO = 0)
    AND ZPARTNERNAME IS NOT NULL
    AND ZPARTNERNAME != ''
    AND NOT ZPARTNERNAME GLOB '*[0-9]*'
ORDER BY ZPARTNERNAME;

Step 6: Execute and Export Results

  1. Click the "Execute" button (▶️) or press F5
  2. You'll see your contacts appear in the results pane below
  3. To export the results:
    • Click File → Export → Table(s) as CSV
    • Or right-click on the results and select "Export as CSV"
    • Choose location and save

Step 7: Import to Your Contacts (Optional)

The we need to convert that export CSV file to a VCF file that can be imported into iCloud to sync to your phone, this means we need a PowerShell script to accomplish this action, this will handle the CSV file based on the data it contains, the script is below:

# CSV to VCF Converter for WhatsApp Contacts
# Converts a CSV file with Name and PhoneNumber columns to a VCF file for iCloud import

param(
    [Parameter(Mandatory=$false)]
    [string]$CsvPath = ".\whatsapp_contacts.csv",
    
    [Parameter(Mandatory=$false)]
    [string]$VcfPath = ".\whatsapp_contacts.vcf"
)

# Function to create a VCF entry for a contact
function Create-VCardEntry {
    param(
        [string]$Name,
        [string]$PhoneNumber
    )
    
    # Clean up the name (remove extra spaces)
    $Name = $Name.Trim()
    
    # Split name into first and last (if possible)
    $nameParts = $Name -split '\s+', 2
    if ($nameParts.Count -eq 2) {
        $firstName = $nameParts[0]
        $lastName = $nameParts[1]
    } else {
        $firstName = $Name
        $lastName = ""
    }
    
    # Clean phone number (ensure it starts with + and has no spaces for the TEL field)
    $cleanPhone = $PhoneNumber.Trim()
    if (-not $cleanPhone.StartsWith("+")) {
        $cleanPhone = "+$cleanPhone"
    }
    
    # Create VCard 3.0 format (best compatibility with iCloud)
    $vcard = @"
BEGIN:VCARD
VERSION:3.0
FN:$Name
N:$lastName;$firstName;;;
TEL;TYPE=CELL:$cleanPhone
END:VCARD
"@
    
    return $vcard
}

# Main script
try {
    # Check if CSV file exists
    if (-not (Test-Path $CsvPath)) {
        Write-Host "Error: CSV file not found at $CsvPath" -ForegroundColor Red
        Write-Host "Please provide the correct path to your CSV file." -ForegroundColor Yellow
        exit 1
    }
    
    Write-Host "Reading CSV file from: $CsvPath" -ForegroundColor Green
    
    # Import CSV file
    $contacts = Import-Csv -Path $CsvPath
    
    # Check if CSV has the required columns
    if (-not ($contacts | Get-Member -Name "Name") -or -not ($contacts | Get-Member -Name "PhoneNumber")) {
        Write-Host "Error: CSV must have 'Name' and 'PhoneNumber' columns" -ForegroundColor Red
        Write-Host "Found columns: $($contacts[0].PSObject.Properties.Name -join ', ')" -ForegroundColor Yellow
        exit 1
    }
    
    Write-Host "Found $($contacts.Count) contacts to convert" -ForegroundColor Cyan
    
    # Create VCF content
    $vcfContent = ""
    $processedCount = 0
    $skippedCount = 0
    
    foreach ($contact in $contacts) {
        # Skip if name or phone is empty
        if ([string]::IsNullOrWhiteSpace($contact.Name) -or [string]::IsNullOrWhiteSpace($contact.PhoneNumber)) {
            $skippedCount++
            Write-Host "  Skipping contact with missing data: $($contact.Name) - $($contact.PhoneNumber)" -ForegroundColor Yellow
            continue
        }
        
        # Create VCard entry
        $vcard = Create-VCardEntry -Name $contact.Name -PhoneNumber $contact.PhoneNumber
        $vcfContent += $vcard + "`n"
        
        $processedCount++
        
        # Show progress every 10 contacts
        if ($processedCount % 10 -eq 0) {
            Write-Host "  Processed $processedCount contacts..." -ForegroundColor Gray
        }
    }
    
    # Save VCF file
    $vcfContent | Out-File -FilePath $VcfPath -Encoding UTF8 -NoNewline
    
    # Summary
    Write-Host "" -ForegroundColor Green
    Write-Host "Conversion Complete!" -ForegroundColor Green
    Write-Host "  - Total contacts processed: $processedCount" -ForegroundColor Cyan
    Write-Host "  - Contacts skipped (missing data): $skippedCount" -ForegroundColor Yellow
    Write-Host "  - VCF file saved to: $VcfPath" -ForegroundColor Green
    
    # Get file size
    $fileInfo = Get-Item $VcfPath
    $fileSizeKB = [math]::Round($fileInfo.Length / 1KB, 2)
    Write-Host "  - File size: $fileSizeKB KB" -ForegroundColor Gray
    
    Write-Host "" -ForegroundColor Magenta
    Write-Host "Next Steps:" -ForegroundColor Magenta
    Write-Host "  1. Go to icloud.com and sign in" -ForegroundColor White
    Write-Host "  2. Click on 'Contacts'" -ForegroundColor White
    Write-Host "  3. Click the gear icon at the bottom left" -ForegroundColor White
    Write-Host "  4. Select 'Import vCard...'" -ForegroundColor White
    Write-Host "  5. Choose the file: $VcfPath" -ForegroundColor White
    Write-Host "  6. Your contacts will sync to your iPhone!" -ForegroundColor White
    
} catch {
    Write-Host "" -ForegroundColor Red
    Write-Host "Error occurred: $_" -ForegroundColor Red
    Write-Host "Stack Trace: $($_.ScriptStackTrace)" -ForegroundColor Red
    exit 1
}

# Optional: Ask if user wants to open the folder containing the VCF file
Write-Host ""
$response = Read-Host "Would you like to open the folder containing the VCF file? (y/n)"
if ($response -eq 'y' -or $response -eq 'Y') {
    $folder = Split-Path -Parent (Resolve-Path $VcfPath)
    Invoke-Item $folder
}

When this is run you should notice that the export will not show errors as below:


This will give you the VCF file as below:


We now need to visit icloud.com on this link > https://www.icloud.com then from here we need to login, once logged you will need the find the contacts (green box) as below:


When the contacts load you will to click on the import icon (the +) then choose Import Contact as below:


Then point this as your VCF file you downloaded and after a short wait you will see the intended import results as below:


We then need to choose the "Create New List" as below:


Then you can give that group a name, in this example I used "WhatsApp Import" as below:


This will then sync those contacts to my iPhone on the next iCloud sync cycle as then you will have your contacts resolved to names in WhatsApp rather than numbers only.

Previous Post Next Post

نموذج الاتصال