This document describes how to integrate Kakao Talk sharing APIs into your service with the Kakao SDK for iOS (hereinafter referred to as 'iOS SDK').
To use the iOS SDK, you must register the iOS platform in advance. Go to [My Application] > [Platform] and register the iOS platform by specifying the Bundle ID.
KakaoSDKShare
(Kakao Talk sharing module) in the Podfile by referring to Set Custom URL Schemes.import KakaoSDKShare
import KakaoSDKShare
import RxKakaoSDKShare
In iOS SDK 2.11.0, the names of the module, classes, and methods related to Kakao Talk sharing have been changed due to the change of its service name. To see more detailed changes, see Version history.
According to your service's purpose and requirements, you need to decide which API to use first by considering their characteristics and difference.
Step 1. Select a type of Messaging APIThere are two types of messaging APIs: the Kakao Talk sharing API and the Kakao Talk messaging API. You need to understand the differences between the two messaging APIs completely by referring to Concepts, and decide which API to use to implement the function to send a message.
Decide which message template to use by referring to Message template > Types.
You can configure a message according to the default template in JSON format or create a custom template in person for your service. Refer to Message configuration method for more details.
After configuring a message, you must call the corresponding API according to the desired message template type. If the request is successful, the iOS SDK launches Kakao Talk or lets a user log in with Kakao Account on a web page, and then shows a list of friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
To make your app launch when a user clicks a button in the Kakao Talk sharing message, you need to set LSApplicationQueriesSchemes
to "kakaolink" in the Configure build settings step. This value is used to create a Custom URL Scheme in the form of "kakao${YOUR_NATIVE_APP_KEY}://kakaolink".
You can also set additional parameters when running the app as needed by using androidExecutionParams
for Android SDK or iosExecutionParams
for iOS SDK. If you have defined the parameters, they are added to Custom URL Schemes as follows.
kakao${YOUR_NATIVE_APP_KEY}://kakaolink?${androidExecutionParams}
kakao${YOUR_NATIVE_APP_KEY}://kakaolink?${iosExecutionParams}
When you configure a Kakao Talk message through the Kakao Talk sharing message API or Kakao Talk messaging API, use one of the classes defined in KakaoSDKTemplate
according to a message type by referring to Message template components. Then, create an object for the desired message type among five types, and define the message content for the template object.
Here are the code snippets showing how to configure a message for each message type.
let title = "Feed messsage"
let description = "Example of Feed messsage"
let feedTemplateJsonStringData =
"""
{
"object_type": "feed",
"content": {
"title": "Strawberry Cheese Cake",
"description": "#Cake #Strawberry #Sampyeong-dong #Cafe #Vibe #BlindDate",
"image_url": "https://mud-kage.kakao.com/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png",
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
}
},
"item_content": {
"profile_text" :"Kakao",
"profile_image_url" :"https://mud-kage.kakao.com/dn/Q2iNx/bhttp://k.kakaocdn.net/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png",
"title_image_url" : "https://mud-kage.kakao.com/dn/Q2iNx/bhttp://k.kakaocdn.net/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png",
"title_image_text" :"Cheese cake",
"title_image_category" : "cake",
"items" : [
{
"item" :"cake1",
"item_op" : "1000 won",
},
{
"item" :"cake2",
"item_op" : "2000 won",
},
{
"item" :"cake3",
"item_op" : "3000 won",
},
{
"item" :"cake4",
"item_op" : "4000 won",
},
{
"item" :"cake5",
"item_op" : "5000 won",
}
],
"sum" :"total",
"sum_op" : "15000 won"
},
"social": {
"comment_count": 45,
"like_count": 286,
"shared_count": 845
},
"buttons": [
{
"title": "View on Web",
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
}
},
{
"title": "View on App",
"link": {
"android_execution_params": "key1=value1&key2=value2",
"ios_execution_params": "key1=value1&key2=value2"
}
}
]
}
""".data(using: .utf8)!
let headerTitle = "Example of List messsage"
let listTemplateJsonStringData =
"""
{
"object_type": "list",
"header_title": "WEEKLY MAGAZINE",
"header_link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
},
"contents": [
{
"title": "My hobby, Table tennis",
"description": "Sports",
"image_url": "https://mud-kage.kakao.com/dn/bDPMIb/btqgeoTRQvd/49BuF1gNo6UXkdbKecx600/kakaolink40_original.png",
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
}
},
{
"title": "Understanding coffee with cream",
"description": "Food",
"image_url": "https://mud-kage.kakao.com/dn/QPeNt/btqgeSfSsCR/0QJIRuWTtkg4cYc57n8H80/kakaolink40_original.png",
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
}
},
{
"title": "Emotional atmosphere",
"description": "Photo",
"image_url": "https://mud-kage.kakao.com/dn/c7MBX4/btqgeRgWhBy/ZMLnndJFAqyUAnqu4sQHS0/kakaolink40_original.png",
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
}
}
],
"buttons": [
{
"title": "View on Web",
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
}
},
{
"title": "View on App",
"link": {
"android_execution_params": "key1=value1&key2=value2",
"ios_execution_params": "key1=value1&key2=value2"
}
}
]
}
""".data(using: .utf8)!
let title = "Location messsage"
let description = "Example of Location messsage"
let locationTemplateJsonStringData =
"""
{
"object_type": "location",
"address_title": "Kakao Pangyo Office Cafe Talk",
"address": "235, Pangyoyeok-ro, Bundang-gu, Seongnam-si, Gyeonggi-do",
"content": {
"description": "Cherry blossom latte 1+1 for this week",
"image_url": "https://mud-kage.kakao.com/dn/bSbH9w/btqgegaEDfW/vD9KKV0hEintg6bZT4v4WK/kakaolink40_original.png",
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.com"
},
"title": "New menu release❤️ Cherry Blossom Latte"
},
"social": {
"comment_count": 45,
"like_count": 286,
"shared_count": 845
}
}
""".data(using: .utf8)!
let title = "Commerce messsage"
let description = "Example of Commerce messsage"
let commerceTemplateJsonStringData =
"""
{
"object_type": "commerce",
"commerce": {
"product_name": "Ivory long dress",
"regular_price": 208800,
"discount_price": 146160,
"discount_rate": 30
},
"content": {
"title": "Ivory long dress (4 Colors)",
"image_url": "https://mud-kage.kakao.com/dn/RY8ZN/btqgOGzITp3/uCM1x2xu7GNfr7NS9QvEs0/kakaolink40_original.png",
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
},
},
"buttons": [
{
"title": "Purchase",
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
}
},
{
"title": "Share",
"link": {
"android_execution_params": "key1=value1&key2=value2",
"ios_execution_params": "key1=value1&key2=value2"
}
}
]
}
""".data(using: .utf8)!
let text = "The Text template provided as a default template can contain text up to 200 characters. The Text template has a text area and a default button. You can also add an additional button. If you use the Kakao Talk sharing, you can send a message with a more extended form of templates, such as sending multiple images and profile information."
let textTemplateJsonStringData =
"""
{
"object_type": "text",
"text": "\(text)",
"link": {
"web_url": "http://dev.kakao.com",
"mobile_web_url": "http://dev.kakao.com"
},
"button_title": "Check it out"
}
""".data(using: .utf8)!
let calendarTemplateJsonStringData =
"""
{
"object_type": "calendar",
"id_type": "\(CalendarTemplate.IdType.Event.rawValue)",
"id": "${YOUR_EVENT_ID}",
"content": {
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
},
"title": "Fashion show for S/S collection",
"description": "Join this upcoming event! To add this event to your calendar, click [일정 등록 하기].",
"image_url": "https://mud-kage.kakao.com/dn/RY8ZN/btqgOGzITp3/uCM1x2xu7GNfr7NS9QvEs0/kakaolink40_original.png"
},
"buttons": [
{
"title": "View event",
"link": {
"mobile_web_url": "https://developers.kakao.com",
"web_url": "https://developers.kakao.com"
}
}
]
}
""".data(using: .utf8)!
As an example, here are the steps to configure and send a Feed message.
Step 1. Figure out template componentsCheck which object you should create for a Feed message by referring to Message template > Feed message. Feed message is defined as the FeedTemplate class.
Create an object in JSON format by referring to the guide and reference. As you check in Step 1, the Feed message contains content
, social
, buttonTitle
, buttons
, and itemContent
components. You must declare the required component, content
for Feed message, in the object.
Create the Templatable
object. If successful, pass the JSON object created in Step 2 when calling the Kakao Talk sharing API or Kakao Talk messaging API.
This API enables you to configure a message in JSON format according to the default template type to use and share it through Kakao Talk.
In the case of shareDefault()
, define the Templatable
object by calling SdkJSONDecoder.custom.decode()
and passing the JSON object created in Configure a message. After that, pass the defined Templatable
object when calling the Kakao Talk sharing API or Kakao Talk messaging API. You can also create the templateObject
and use it when sending a message by referring to Advanced: Create a message using constructor.
To figure out if it is possible to share a message through Kakao Talk, call isKakaoTalkSharingAvailable()
that checks if Kakao Talk has been installed. If Kakao Talk is installed, call shareDefault()
that shares a message through Kakao Talk. If not installed, call makeDefaultUrl()
to declare a URL for sharing and open the URL WebView or a default browser.
Name | Type | Description | Required |
---|---|---|---|
templatable | Templatable |
Object of the message template to be sent. Use one of the following templates: FeedTemplate ListTemplate LocationTemplate CommerceTemplate TextTemplate CalendarTemplate You must create an object of the class for the desired template by referring to Configure a message. |
O |
serverCallbackArgs | [String:String]? |
Used when you want to get a callback from Kakao to your service server when a message is successfully sent. Refer to Set Kakao Talk sharing success callback. |
X |
//in ViewController
var safariViewController : SFSafariViewController? // to keep instance
//...
guard let templatable = try? SdkJSONDecoder.custom.decode(FeedTemplate.self, from: feedTemplateJsonStringData) else {
return
}
// Check if Kakao Talk has been installed.
if ShareApi.isKakaoTalkSharingAvailable() {
// Kakao Talk sharing is available.
// For 'templatable', refer to the 'Configure a message' guide.
ShareApi.shared.shareDefault(templatable: templatable) {(sharingResult, error) in
if let error = error {
print(error)
}
else {
print("shareDefault() success.")
if let sharingResult = sharingResult {
UIApplication.shared.open(sharingResult.url,
options: [:], completionHandler: nil)
}
}
}
else {
// If Kakao Talk is not installed, it is recommended to share URI via web.
// You can use custom webView or default browser.
// Example of sharing URI via web
if let url = ShareApi.shared.makeDefaultUrl(templatable: templatable) {
self.safariViewController = SFSafariViewController(url: url)
self.safariViewController?.modalTransitionStyle = .crossDissolve
self.safariViewController?.modalPresentationStyle = .overCurrentContext
self.present(self.safariViewController!, animated: true) {
print("Succeeded in presenting web.")
}
}
}
// Class member property
let disposeBag = DisposeBag()
// For 'templatable', refer to the 'Configure a message' guide.
if let templatable = try? SdkJSONDecoder.custom.decode(FeedTemplate.self, from: feedTemplateJsonStringData) {
ShareApi.shared.rx.shareDefault(templatable:templatable)
.subscribe(onSuccess: { (sharingResult) in
print("shareDefault() success.")
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
}
Calling shareDefault()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
shareDefault()
returns SharingResult. Because the Kakao Talk sharing API does not inform the result of message delivery, implement the Kakao Talk sharing success callback function.
Name | Type | Description | Required |
---|---|---|---|
url | URL |
URL to invoke Kakao Talk sharing with the requested template. | O |
argumentMsg | [String : String] |
Result of templateArgs validation. | X |
warningMsg | [String : String] |
Validation result of template . | O |
This API enables you to customize a template in [Tools] > [Message Template Builder] and send a message through Kakao Talk.
To figure out if it is possible to share a message through Kakao Talk, call isKakaoTalkSharingAvailable()
that checks if Kakao Talk has been installed. If Kakao Talk is installed, call shareCustom()
that shares a message through Kakao Talk. If not installed, call makeCustomUrl()
to declare a URL for sharing and open the URL WebView or a default browser.
Name | Type | Description | Required |
---|---|---|---|
templateId | Int64 |
Template ID of the custom template registered in [Tools] > [Message Template Builder]. Refer to Message template builder. |
O |
templateArgs | [String:String]? |
If the specified template contains a user argument, use this parameter to pass key-value pairs. | X |
serverCallbackArgs | [String:String]? |
Used when you want to get a callback from Kakao to your service server when a message is successfully sent. Refer to Set Kakao Talk sharing success callback. |
X |
let templateId : Int64 = 12345
// Check if Kakao Talk has been installed.
if ShareApi.isKakaoTalkSharingAvailable() {
// Kakao Talk sharing is available.
ShareApi.shared.shareCustom(templateId: templateId, templateArgs:["title":"This is title.", "description":"This is description."]) {(sharingResult, error) in
if let error = error {
print(error)
}
else {
print("shareCustom() success.")
if let sharingResult = sharingResult {
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}
}
}
}
else {
// If Kakao Talk is not installed, it is recommended to share URI via web.
// You can use custom webView or default browser.
// Example of sharing URI via web
if let url = ShareApi.shared.makeCustomUrl(templateId: templateId, templateArgs:["title":"This is title.", "description":"This is description."]) {
self.safariViewController = SFSafariViewController(url: url)
self.safariViewController?.modalTransitionStyle = .crossDissolve
self.safariViewController?.modalPresentationStyle = .overCurrentContext
self.present(self.safariViewController!, animated: true) {
print("Succeeded in presenting web.")
}
}
}
// Class member property
let disposeBag = DisposeBag()
let templateId : Int64 = 12345
ShareApi.shared.rx.shareCustom(templateId:templateId, templateArgs:["title":"This is title.", "description":"This is description."])
.subscribe(onSuccess: { (sharingResult) in
print("shareCustom() success.")
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
Calling shareCustom()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
shareCustom()
returns SharingResult. Because the Kakao Talk sharing API does not inform the result of message delivery, implement the Kakao Talk sharing success callback function.
This API scraps a web page, configures a message based on the scraped web page information, and then sends it through Kakao Talk.
To figure out if it is possible to share a message through Kakao Talk, call isKakaoTalkSharingAvailable()
that checks if Kakao Talk has been installed. If Kakao Talk is installed, call shareScrap()
that shares a message through Kakao Talk. If not installed, call makeScrapUrl()
to declare a URL for sharing and open the URL WebView or a default browser.
Name | Type | Description | Required |
---|---|---|---|
requestUrl | String |
Web page URL to be scraped. Its domain must match the domain registered on the Kakao Developers. |
O |
serverCallbackArgs | [String:String]? |
Used when you want to get a callback from Kakao to your service server when a message is successfully sent. Refer to Set Kakao Talk sharing success callback. |
X |
let requestUrl = "https://developers.kakao.com"
// Check if Kakao Talk has been installed.
if ShareApi.isKakaoTalkSharingAvailable() {
// Kakao Talk sharing is available.
ShareApi.shared.shareScrap(requestUrl: requestUrl) {(sharingResult, error) in
if let error = error {
print(error)
}
else {
print("shareScrap() success.")
if let sharingResult = sharingResult {
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}
}
}
}
else {
// If Kakao Talk is not installed, it is recommended to share URI via web.
// You can use custom webView or default browser.
// Example of sharing URI via web
if let url = ShareApi.shared.makeScrapUrl(requestUrl: requestUrl) {
self.safariViewController = SFSafariViewController(url: url)
self.safariViewController?.modalTransitionStyle = .crossDissolve
self.safariViewController?.modalPresentationStyle = .overCurrentContext
self.present(self.safariViewController!, animated: true) {
print("Succeeded in presenting web.")
}
}
}
// Class member property
let disposeBag = DisposeBag()
let requestUrl = "https://developers.kakao.com"
ShareApi.shared.rx.shareScrap(requestUrl: requestUrl)
.subscribe(onSuccess: { (sharingResult) in
print("shareScrap() success.")
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
Calling shareScrap()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
shareScrap()
returns SharingResult. Because the Kakao Talk sharing API does not inform the result of message delivery, implement the Kakao Talk sharing success callback function.
This API scraps a web page, configures a message based on the scraped web page information, and then sends it through Kakao Talk. You can use a custom template registered in [Tools] > [Message Template Builder] when requesting to send a scrap message.
To figure out if it is possible to share a message through Kakao Talk, call isKakaoTalkSharingAvailable()
that checks if Kakao Talk has been installed. If Kakao Talk is installed, call shareScrap
that shares a message through Kakao Talk. If not installed, call makeScrapUrl
to declare a URL for sharing and open the URL WebView or a default browser.
Name | Type | Description | Required |
---|---|---|---|
requestUrl | String |
Web page URL to be scraped. Its domain must match the domain registered on the Kakao Developers. |
O |
templateId | Int64 |
Used when you want to send a scrap message with the template registered in [Tools] > [Message Template Builder]. Specify the ID of the template to apply. When you use this parameter, the scraped content is applied in the template with the specified templateId . |
O |
templateArgs | [String:String]? |
If you specify templateId and the specified template contains other user arguments besides the default argument keys, pass the user arguments using this parameter in key:value format.You cannot overwrite the scrap result. |
X |
serverCallbackArgs | [String:String]? |
Used when you want to get a callback from Kakao to your service server when a message is successfully sent. Refer to Set Kakao Talk sharing success callback. |
X |
let requestUrl = "https://developers.kakao.com"
let templateId : Int64 = 12345
// Check if Kakao Talk has been installed.
if ShareApi.isKakaoTalkSharingAvailable() {
// Kakao Talk sharing is available.
ShareApi.shared.shareScrap(requestUrl: requestUrl, templateId: templateId) {(sharingResult, error) in
if let error = error {
print(error)
}
else {
print("shareScrap() success.")
if let sharingResult = sharingResult {
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}
}
}
else {
// If Kakao Talk is not installed, it is recommended to share URI via web.
// You can use custom webView or default browser.
// Example of sharing URI via web
if let url = ShareApi.shared.makeScrapUrl(requestUrl: requestUrl, templateId: templateId) {
self.safariViewController = SFSafariViewController(url: url)
self.safariViewController?.modalTransitionStyle = .crossDissolve
self.safariViewController?.modalPresentationStyle = .overCurrentContext
self.present(self.safariViewController!, animated: true) {
print("Succeeded in presenting web.")
}
}
}
// Class member property
let disposeBag = DisposeBag()
let requestUrl = "https://developers.kakao.com"
let templateId : Int64 = 12345
ShareApi.shared.rx.shareScrap(requestUrl: requestUrl, templateId: templateId)
.subscribe(onSuccess: { (sharingResult) in
print("shareScrap() success.")
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
Calling shareScrap()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
shareScrap()
returns SharingResult. Because the Kakao Talk sharing API does not inform the result of message delivery, implement the Kakao Talk sharing success callback function.
The Kakao Talk sharing success callback is a function to send a callback request to the URL specified on Kakao Developers when a Kakao Talk sharing message is successfully sent to friends or a chatroom selected by a user. This function is only available for Kakao Talk sharing API, not for Kakao Talk messaging API.
To use this feature, you need to:
To use the Kakao Talk sharing success callback function, you must specify a custom parameter through serverCallbackArgs
. Otherwise, you cannot receive Kakao Talk sharing success callbacks even though you registered a callback URL for Kakao Talk sharing in [My Application]. When your service server receives a Kakao Talk sharing success callback, you can figure out additional information through the predefined custom parameters, such as what content the user has shared.
To pass additional information when requesting the Kakao Talk sharing API, declare serverCallbackArgs
, and pass keys and values as a Dictionary
. Here is a code snippet showing how to set parameters for Kakao Talk sharing success callback.
// Template ID.
let templateId : Int64 = 12345;
// Template arguments.
let templateArgs = ["title": "This is the title area.", "description": "This is the description area."]
// Information passed from Kakao server.
let serverCallbackArgs = ["user_id": "abcd", "product_id": "1234"]
// Check if Kakao Talk has been installed.
if ShareApi.isKakaoTalkSharingAvailable() {
// Kakao Talk sharing is available.
ShareApi.shared.shareCustom(templateId:templateId,
templateArgs:templateArgs,
serverCallbackArgs: serverCallbackArgs) { (sharingResult, error) in
if let error = error {
print(error)
}
else {
print("shareCustom() success.")
if let sharingResult = sharingResult {
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}
}
}
}
else {
// If Kakao Talk is not installed, it is recommended to share URI via web.
// You can use custom webView or default browser.
// Example of sharing URI via web
if let url = ShareApi.shared.makeCustomUrl(templateId:templateId,
templateArgs:templateArgs,
serverCallbackArgs: serverCallbackArgs) {
self.safariViewController = SFSafariViewController(url: url)
self.safariViewController?.modalTransitionStyle = .crossDissolve
self.safariViewController?.modalPresentationStyle = .overCurrentContext
self.present(self.safariViewController!, animated: true) {
print("Succeeded in presenting web.")
}
}
}
// Class member property
let disposeBag = DisposeBag()
// Template ID
let templateId : Int64 = 12345;
// Template arguments
let templateArgs = ["title": "This is the title area.", "description": "This is the description area."]
// Information passed from Kakao server.
let serverCallbackArgs = ["user_id": "abcd", "product_id": "1234"]
ShareApi.shared.rx.shareCustom(templateId:templateId,
templateArgs:templateArgs,
serverCallbackArgs: serverCallbackArgs)
.subscribe(onSuccess: { (sharingResult) in
print("shareCustom() success.")
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
}
If the Kakao Talk sharing message is successfully sent, Kakao sends a Kakao Talk sharing success callback including the specified parameters to the callback URL of your service server. For more information on the callback request, refer to Reference Information > Kakao Talk sharing success callback.
You can attach images to a Kakao Talk sharing message by passing an image URL when configuring a message template or uploading images in the Message template builder in advance. To use the image file stored on your device for a message, you must upload the image file to the server first to obtain its URL value.
If it is difficult to obtain the image file URL, you can either upload an image file to the Kakao Talk sharing server or scrap it. The images uploaded to the Kakao Talk sharing server are stored for up to 20 days and automatically deleted after the period.
To upload an image, call the imageUpload()
method defined in ShareApi
. You can only upload an image with a file size of 2 MB or less.
Name | Type | Description | Required |
---|---|---|---|
image | UIImage |
Image file to be uploaded. | O |
secureResource | Bool |
Whether to use HTTPS for the image URL scheme. - true : HTTPS is used. - false : HTTP is used.(Default: true ) |
X |
if let image = UIImage(named: "sample1") {
ShareApi.shared.imageUpload(image:image) { [weak self] (imageUploadResult, error) in
if let error = error {
print(error)
}
else {
print("imageUpload() success.")
}
}
}
// Class member property
let disposeBag = DisposeBag()
if let image = UIImage(named: "sample1") {
ShareApi.shared.rx.imageUpload(image:image)
.subscribe(onSuccess: { (imageUploadResult) in
print("imageUpload() success.")
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
}
To use an image by scraping an image uploaded on the web page, call the imageScrap()
method defined in ShareApi
.
Name | Type | Description | Required |
---|---|---|---|
imageUrl | URL |
URL of the image to be scrapped. | O |
secureResource | Bool |
Whether to use HTTPS for the image URL scheme. If true , HTTPS is used. (Default: true ) |
X |
if let url = URL(string:"https://t1.kakaocdn.net/kakaocorp/Service/KakaoTalk/pc/slide/talkpc_theme_01.jpg") {
ShareApi.shared.imageScrap(imageUrl: url, completion: { [weak self] (imageUploadResult, error) in
if let error = error {
print(error)
}
else {
print("imageUpload() success.")
}
})
}
// Class member property
let disposeBag = DisposeBag()
if let url = URL(string:"https://t1.kakaocdn.net/kakaocorp/Service/KakaoTalk/pc/slide/talkpc_theme_01.jpg") {
ShareApi.shared.rx.imageScrap(imageUrl: url)
.subscribe(onSuccess: { (imageUploadResult) in
print(String(describing:imageUploadResult))
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
}
When the request is successful, the information of the uploaded image is returned. You can use the image URL when configuring a message.
Name | Type | Description | Required |
---|---|---|---|
infos | ImageInfos |
The uploaded image information. | O |
Name | Type | Description | Required |
---|---|---|---|
original | ImageInfo |
The original image information. | O |
Name | Type | Description | Required |
---|---|---|---|
url | URL |
URL of the uploaded image. | O |
contentType | String |
Format of the uploaded image. | O |
length | Int |
File size of the uploaded image in bytes. | O |
width | Int |
Width of the uploaded image in pixels. | O |
height | Int |
Height of the uploaded image in pixels. | O |
You can also creat a message by using a constructor for a template class, as well as configuring a message in JSON format according to message types. With the method using a constructor, you can identify and define components more explicitly. However, you cannot use a template class for each message type directly when requesting to send a message. Instead, you should use it to create the templateObject
object to be passed as a parameter(or argument).
let link = Link(webUrl: URL(string:"https://developers.kakao.com"),
mobileWebUrl: URL(string:"https://developers.kakao.com"))
let appLink = Link(androidExecutionParams: ["key1": "value1", "key2": "value2"],
iosExecutionParams: ["key1": "value1", "key2": "value2"])
let button1 = Button(title: "View on Web", link: link)
let button2 = Button(title: "View on App", link: appLink)
let social = Social(likeCount: 286,
commentCount: 45,
sharedCount: 845)
let content = Content(title: "Strawberry Cheese Cake",
imageUrl: URL(string:"https://mud-kage.kakao.com/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png")!,
description: "#Cake #Strawberry #Sampyeong-dong #Cafe #Vibe #BlindDate",
link: link)
let feedTemplate = FeedTemplate(content: content, social: social, buttons: [button1, button2])
//Encode message template.
if let feedTemplateJsonData = (try? SdkJSONEncoder.custom.encode(feedTemplate)) {
//Convert the created message template object to a json object.
if let templateJsonObject = SdkUtils.toJsonObject(feedTemplateJsonData) {
ShareApi.shared.shareDefault(templateObject:templateJsonObject) {(sharingResult, error) in
if let error = error {
errorHandler(error)
}
else {
print("shareDefault(templateObject:templateJsonObject) success.")
//Do something
guard let sharingResult = sharingResult else { return }
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}
}
}
}
// Class member property
let disposeBag = DisposeBag()
let link = Link(webUrl: URL(string:"https://developers.kakao.com"),
mobileWebUrl: URL(string:"https://developers.kakao.com"))
let appLink = Link(androidExecutionParams: ["key1": "value1", "key2": "value2"],
iosExecutionParams: ["key1": "value1", "key2": "value2"])
let button1 = Button(title: "View on Web", link: link)
let button2 = Button(title: "View on App", link: appLink)
let social = Social(likeCount: 286,
commentCount: 45,
sharedCount: 845)
let content = Content(title: "Strawberry Cheese Cake",
imageUrl: URL(string:"https://mud-kage.kakao.com/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png")!,
description: "#Cake #Strawberry #Sampyeong-dong #Cafe #Vibe #BlindDate",
link: link)
let feedTemplate = FeedTemplate(content: content, social: social, buttons: [button1, button2])
//Encode message template.
if let feedTemplateJsonData = (try? SdkJSONEncoder.custom.encode(feedTemplate)) {
//Convert the created message template object to a json object.
if let templateJsonObject = SdkUtils.toJsonObject(feedTemplateJsonData) {
ShareApi.shared.rx.shareDefault(templateObject:templateJsonObject)
.subscribe(onSuccess: { (sharingResult) in
print("success.")
//Do something
UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil)
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
}
}
To see how to use the Messaging APIs using the Legacy Kakao SDK for iOS, see Message guide for Legacy iOS SDK.
It is highly recommended to migrate to the new version of iOS SDK as soon as possible because the Legacy version may not be supported anymore.