2014-07-24 288 views
1

我需要知道您是否可以用「abid = + 2827272727」命令打開whatapps中的聯繫人。whatapps打開窗口

NSURL *whatsappURL = [NSURL 
URLWithString:@"whatsapp://send?abid=+2827272727&text=Hola!"]; 
if ([[UIApplication sharedApplication] canOpenURL:whatsappURL]) { 
    [[UIApplication sharedApplication] openURL:whatsappURL]; 
} 

回答

1

是的,你可以,但請注意,阿比德不是聯繫人電話號碼。 這是ABRecordGetRecordID

試試這個代碼來打開你的地址簿中名爲「你的名字」的聯繫人的WhatsApp。

// Fetch the address book 
    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL,NULL); 
    dispatch_semaphore_t sema = dispatch_semaphore_create(0); 
    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) { 
     dispatch_semaphore_signal(sema); 
    }); 
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); 

    // find user 
    CFStringRef searchQuery = CFSTR("Your Contact Name"); 

    CFArrayRef array = ABAddressBookCopyPeopleWithName (addressBook,searchQuery); 
    int items = CFArrayGetCount(array); 
    NSLog(@"found %i persons",items); 

    int abid = 0; 
    for (int i = 0; i < items; i++) 
    { 
     ABRecordRef person = CFArrayGetValueAtIndex(array, i); 
     abid = ABRecordGetRecordID(person); 
     NSLog(@"found person %i ",abid); 
     break; 
    } 

    if (abid > 0) 
    { 
     NSString* url = [NSString stringWithFormat:@"whatsapp://send?abid=%i&text=Hola",abid]; 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; 
    }