How to handle instant messaging URL from Contacts application (like Facebook)

此生再无相见时 提交于 2019-12-13 07:41:20

问题


I have a feeling this one's going to be hard.

On iOS7, the Facebook app has the ability to be launched directly from the iOS Contact application, by clicking on any contact's IM (instant messaging) info:

This only works if you enable Facebook to have access to your contacts, obviously, but I'm wondering how they do it?
I know of the Custom URL handling, which is perfect for handling specially crafted URLs, but in this case, putting my own forged url ( "myapp://gui13@lol.com" ) in an IM contact information doesn't trigger the functionnality.

There's only one way that I found that triggers the launch of my app from the Contact application, which is to save my URL into a "link"-type information about the contact.
The bad drawback is that this "link" type information is not synced with the remote address books...

So my question is: how can I tell iOS to launch my app when the user clicks an IM information in the Contact app.?

Or the bad news... Facebook is an Apple-blessed app, just like Twitter, which enables it to have this kind of advanced interaction with Apple's apps?


回答1:


It can be achieved. As you said you have to create custom URL scheme for you app (if someone doesn't know how to this, here is tutorial).

Now you have to add kABPersonSocialProfileProperty to your contact (existing or new one).

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
ABRecordRef contact = ABPersonCreate();

/* implement standard contact info */
/* the social part below */

ABMultiValueRef social = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
ABMultiValueAddValueAndLabel(social, (__bridge CFTypeRef)([NSDictionary dictionaryWithObjectsAndKeys:
                                                           @"your app service name ", kABPersonSocialProfileServiceKey, //will be visible in contact
                                                           @"contact firstname / lastname / identifier", kABPersonSocialProfileUsernameKey, //will be visible in contact
                                                           @"your app custom url scheme", kABPersonSocialProfileURLKey, //url which will be open onclick event
                                                           nil]), (__bridge CFStringRef)@"your app special identifier", NULL); //to know to which app this social belongs to. I believe it is for search purposes

ABRecordSetValue(contact, kABPersonSocialProfileProperty, social, NULL);
CFRelease(social);

/* save contact */

For sake of completeness here is tutorial which explains deeply how to create and add contact to address book.

Hope it will help someone.



来源:https://stackoverflow.com/questions/21437269/how-to-handle-instant-messaging-url-from-contacts-application-like-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!