56

I am making a function in iOS where I am adding a new contact to a user's address book programmatically, which is all going fine. The next step is to send that new contact a message via Whatsapp, which is not very hard either. The purpose is to directly show the chat screen with the new contact. The problem is however that Whatsapp does sync it's contacts now and then. I am using the following intent for Whatsapp:

var whatsappUrl = (NSURL(string:"whatsapp://send?text=\(encodedmessage)&abid=\(id)"))      

Where the message is an encoded string and the id is the id from the freshly added contact. When my program opens Whatsapp with that method, everything is going fine when the contact was already in the address book. When that contact is newly added, the Whatsapp screen will not go directly to that screen. Instead it will show the picker for all the contacts.

Long story short, I want to refresh Whatsapp's contacts using my code, in order to send the user directly to the Whatsapp chat screen of the new contact instead of the contact picker screen, which is because Whatsapp's contacts are not synced yet with the new contact.

James Webster
  • 31,873
  • 11
  • 70
  • 114
Niels Robben
  • 1,637
  • 4
  • 17
  • 24
  • Could you come with solution? I doubt we can just redirect to whatsApp but can not take control over it to refresh its contacts! – BaSha Jan 23 '15 at 09:36
  • Hi BaSha, No I haven't come up with a suitable solution nor could I find a solution on the web.. :( – Niels Robben Jan 23 '15 at 10:30
  • 1
    I looked around and tried to solve this, but Whatsapp seems to load the guess url before it refreshes the contact list. Doesn't seem like it's possible... – Laurent Rivard Jan 27 '15 at 14:09
  • 1
    Hi Laurent, that's a pity! Thanks for trying though! – Niels Robben Jan 27 '15 at 16:27
  • 6
    as far as i could notice, whatsapp refreshes its list of contacts on app launch, but not when the app is opened from the background. so i think, ur scenario would work when the app isn't in the background. besides that, not much you can do – Ramy Kfoury Apr 27 '15 at 08:15
  • 6
    Maybe filing a bug report to WhatsApp can help. – Ingo Dellwig Jul 08 '15 at 11:16
  • I found something that may help you: https://github.com/WHAnonymous/Chat-API although it will probably get your app rejected from the app store, you can have a look at some of the private whatsapp APIs. Sorry for being ~10 months late though – kabiroberai Oct 20 '15 at 17:24
  • @kabiroberai, it is certainly something to look in to! Thanks for the effort! :) – Niels Robben Oct 22 '15 at 20:24
  • @NielsRobben no problem :) – kabiroberai Oct 23 '15 at 09:09
  • I'm sure you've seen this, but [here's how to refresh it manually](http://ccm.net/faq/35516-whatsapp-messenger-how-to-refresh-your-contact-list) - just collecting info :) – Cullub Dec 25 '15 at 21:57
  • Maybe this workaround might help http://stackoverflow.com/questions/17711325/abid-in-whatsapp-url-schemes – Sepheroth Jan 23 '16 at 02:09

2 Answers2

1

It is recommended that you should not interact with other 3rd party apps unless they provide a handle to interact. Which is already given by whatsapp as openurl scheme.

In case you have the contact that is removed or added you should address the issue first in your app so it doesn't/does initiate the action to open App before evening checking with wahtsapp.

You can use a great library that APAddressBook to do the contact add and modified check.

codelover
  • 1,113
  • 10
  • 28
0

Obviously you can't. Since WhatsApp's sync procedure is done inside the app itself, you will not be able to do a sync outside the app. What you could try to do is adding the full number with country code in the URL, then parse it to WhatsApp. WhatsApp should do a presence subscription, and so you will be able to send a message to that number.

gi097
  • 7,313
  • 3
  • 27
  • 49