페이지 이동경로
  • Docs>
  • Message>
  • Kakao Link: iOS

Message

Kakao Link: iOS

This document describes how to integrate Kakao Link APIs into your service with the Kakao SDK for iOS (hereinafter referred to as 'iOS SDK').

Before you begin

Register iOS Platform

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.

Add modules

  1. Add the KakaoSDKLink(Kakao Link module) in the Podfile by referring to Set Custom URL Schemes.
  2. Add the import statements for the Kakao Link module as follows.
Sample
Swift
RxSwift
import KakaoSDKLink
import KakaoSDKLink
import RxKakaoSDKLink

Choose an API to use

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 API

There are two types of messaging APIs: Kakao Link and Kakao Talk messaging API. You need to understand the differences between the two messaging APIs completely by referring to Understand concepts, and decide which API to use to implement the function to send a message.

Step 2. Select a message type and configuration method

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.

Set Custom URL Scheme

To make your app launch when a user clicks a button in the Kakao Link 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}

Configure a message

When you configure a Kakao Talk message through the Kakao Link or Kakao Talk messaging APIs, 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.

Feed
List
Location
Commerce
Text
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 Kakao Link, 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)!

As an example, here are the steps to configure and send a Feed message.

Step 1. Figure out template components

Check which object you should create for a Feed message by referring to Message template > Feed message. Feed message is defined as the FeedTemplate class.

Step 2.Define template components

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.

Step 3.Request to send a message

Create the Templatable object. If successful, pass the JSON object created in Step 2 when calling Kakao Link or Kakao Talk messaging API.

Send message with default template

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 defaultLink(), 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 Kakao Link 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 the isKakaoLinkAvailable method that checks if Kakao Talk has been installed. If Kakao Talk is installed, call defaultLink that shares a message through Kakao Talk. If not installed, call makeSharerUrlforDefaultLink to declare a URL for sharing and open the URL WebView or a default browser.

Parameter
Name Type Description Required
templatable Templatable Object of the message template to be sent.
You must create an object of the class for the desired template.
Refer 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 Link success callback.
X
Sample
Swift
RxSwift
//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 LinkApi.isKakaoLinkAvailable() {
    // Possible to share Kakao Link message through Kakao Talk.
    // For 'templatable', refer to the 'Configure a message' guide.
    LinkApi.shared.defaultLink(templatable: templatable) {(linkResult, error) in
    if let error = error {
        print(error)
    }
    else {
        print("defaultLink() success.")

        if let linkResult = linkResult {
            UIApplication.shared.open(linkResult.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 = LinkApi.shared.makeSharerUrlforDefaultLink(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) {
    LinkApi.shared.rx.defaultLink(templatable:templatable)
        .subscribe(onSuccess: { (linkResult) in
            print("defaultLink() success.")
            
            UIApplication.shared.open(linkResult.url, options: [:], completionHandler: nil)
        }, onFailure: {error in
            print(error)
        })
        .disposed(by: disposeBag)
}
Return data

Calling defaultLink() 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.

defaultLink() returns LinkResult. Since the Kakao Link API does not inform the result of message delivery, implement Kakao Link success callback.

LinkResult
Name Type Description Required
url URL Kakao Link URL to invoke Kakao link with the requested template. O
argumentMsg [String : String] Result of templateArgs validation. X
warningMsg [String : String] Validation result of template . O

Send message with custom template

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 the isKakaoLinkAvailable method that checks if Kakao Talk has been installed. If Kakao Talk is installed, call customLink that shares a message through Kakao Talk. If not installed, call makeSharerUrlforCustomLink to declare a URL for sharing and open the URL WebView or a default browser.

Parameter
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 Link success callback.
X
Sample
Swift
RxSwift
let templateId : Int64 = 12345

// Check if Kakao Talk has been installed.
if LinkApi.isKakaoLinkAvailable() {
    // Possible to share Kakao Link message through Kakao Talk.
    LinkApi.shared.customLink(templateId: templateId, templateArgs:["title":"This is title.", "description":"This is description."]) {(linkResult, error) in
        if let error = error {
            print(error)
        }
        else {
            print("customLink() success.")
            if let linkResult = linkResult {
                UIApplication.shared.open(linkResult.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 = LinkApi.shared.makeSharerUrlforCustomLink(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

LinkApi.shared.rx.customLink(templateId:templateId, templateArgs:["title":"This is title.", "description":"This is description."])
    .subscribe(onSuccess: { (linkResult) in
        print("customLink() success.")
        
        UIApplication.shared.open(linkResult.url, options: [:], completionHandler: nil)
    }, onFailure: {error in
        print(error)
    })
    .disposed(by: disposeBag)
Return data

Calling customLink() 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.

customLink() returns LinkResult. Since the Kakao Link API does not inform the result of message delivery, implement Kakao Link success callback.

Send scrap message with default template

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 the isKakaoLinkAvailable method that checks if Kakao Talk has been installed. If Kakao Talk is installed, call scrapLink that shares a message through Kakao Talk. If not installed, call makeSharerUrlforScrapLink to declare a URL for sharing and open the URL WebView or a default browser.

Parameter
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 Link success callback.
X
Sample
Swift
RxSwift
let requestUrl = "https://developers.kakao.com"

// Check if Kakao Talk has been installed.
if LinkApi.isKakaoLinkAvailable() {
    // Possible to share Kakao Link message through Kakao Talk.
    LinkApi.shared.scrapLink(requestUrl: requestUrl) {(linkResult, error) in
        if let error = error {
            print(error)
        }
        else {
            print("scrapLink() success.")
            if let linkResult = linkResult {
                UIApplication.shared.open(linkResult.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 = LinkApi.shared.makeSharerUrlforScrapLink(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"

LinkApi.shared.rx.scrapLink(requestUrl: requestUrl)
    .subscribe(onSuccess: { (linkResult) in
        print("scrapLink() success.")
        
        UIApplication.shared.open(linkResult.url, options: [:], completionHandler: nil)
    }, onFailure: {error in
        print(error)
    })
    .disposed(by: disposeBag)
Return data

Calling scrapLink() 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.

scrapLink() returns LinkResult. Since the Kakao Link API does not inform the result of message delivery, implement Kakao Link success callback.

Send scrap message with custom template

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 the isKakaoLinkAvailable method that checks if Kakao Talk has been installed. If Kakao Talk is installed, call scrapLink that shares a message through Kakao Talk. If not installed, call makeSharerUrlforScrapLink to declare a URL for sharing and open the URL WebView or a default browser.

Parameter
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 specifed 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 Link success callback.
X
Sample
Swift
RxSwift
let requestUrl = "https://developers.kakao.com"
let templateId : Int64 = 12345

// Check if Kakao Talk has been installed.
if LinkApi.isKakaoLinkAvailable() {
    // Possible to share Kakao Link message through Kakao Talk.
    LinkApi.shared.scrapLink(requestUrl: requestUrl, templateId: templateId) {(linkResult, error) in
    if let error = error {
        print(error)
    }
    else {
        print("scrapLink() success.")
        if let linkResult = linkResult {
            UIApplication.shared.open(linkResult.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 = LinkApi.shared.makeSharerUrlforScrapLink(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


LinkApi.shared.rx.scrapLink(requestUrl: requestUrl, templateId: templateId)
    .subscribe(onSuccess: { (linkResult) in
        print("scrapLink() success.")
        
        UIApplication.shared.open(linkResult.url, options: [:], completionHandler: nil)
    }, onFailure: {error in
        print(error)
    })
    .disposed(by: disposeBag)
Return data

Calling scrapLink() 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.

scrapLink() returns LinkResult. Since the Kakao Link API does not inform the result of message delivery, implement Kakao Link success callback.

Set Kakao Link success callback

The Kakao Link success callback is a function to send a callback request to the URL specified on Kakao Developers when a Kakao Link message is successfully sent to friends or a chatroom selected by a user. This function is only available for Kakao Link API, not for Kakao Talk messaging API.

To use this feature, you need to:

  1. Set the callback URL and request method by referring to Prerequisites > Set Kakao Link success callback.
  2. Build a server to receive a Kakao Link success callback.
  3. Set a custom parameter to pass additional information when requesting the Kakao Link API.
  4. Implement a process to handle the callback delivered to your service server's callback URL.

To use the Kakao Link callback function, you must specify a custom parameter through serverCallbackArgs. Otherwise, Kakao Link success callback is not delivered even though you registered Kakao Link callback URL in [My Application]. When your service server receives a Kakao Link 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 Link API, declare serverCallbackArgs, and pass keys and values as a Dictionary. Here is a code snippet showing how to set parameters for Kakao Link success callback.

Sample
Swift
RxSwift
// 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 LinkApi.isKakaoLinkAvailable() {
    // Possible to share Kakao Link message through Kakao Talk.
    LinkApi.shared.customLink(templateId:templateId,
                            templateArgs:templateArgs,
                            serverCallbackArgs: serverCallbackArgs) { (linkResult, error) in
        if let error = error {
            print(error)
        }
        else {
            print("customLink() success.")
            if let linkResult = linkResult {
                UIApplication.shared.open(linkResult.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 = LinkApi.shared.makeSharerUrlforCustomLink(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"]

LinkApi.shared.rx.customLink(templateId:templateId,
                            templateArgs:templateArgs,
                            serverCallbackArgs: serverCallbackArgs)
    .subscribe(onSuccess: { (linkResult) in
        print("customLink() success.")
        
        UIApplication.shared.open(linkResult.url, options: [:], completionHandler: nil)
    }, onFailure: {error in
        print(error)
    })
    .disposed(by: disposeBag)
}

If the Kakao Link message has successfully been delivered, Kakao sends a success callback including the specified parameters to the Kakao Link callback URL of your service server. For more information on the callback request, refer to Reference Information > Kakao Link success callback.

Upload image

You can attach images to a Kakao Link 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 Link server or scrap it. The images uploaded to the Kakao Link server are stored for up to 20 days and automatically deleted after the period.

Uploading image

To upload an image, call the imageUpload() method defined in LinkApi. You can only upload an image with a file size of 2 MB or less.

Parameter
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
Sample
Swift
RxSwift
if let image = UIImage(named: "sample1") {
    LinkApi.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") {
    LinkApi.shared.rx.imageUpload(image:image)
        .subscribe(onSuccess: { (imageUploadResult) in
            print("imageUpload() success.")
            
        }, onFailure: {error in
            print(error)
        })
        .disposed(by: disposeBag)
}

Scraping image

To use an image by scraping an image uploaded on the web page, call the imageScrap() method defined in LinkApi.

Parameter
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
Sample
Swift
RxSwift
if let url = URL(string:"https://t1.kakaocdn.net/kakaocorp/Service/KakaoTalk/pc/slide/talkpc_theme_01.jpg") {
    LinkApi.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") {
    LinkApi.shared.rx.imageScrap(imageUrl: url)
        .subscribe(onSuccess: { (imageUploadResult) in
            print(String(describing:imageUploadResult))            
        }, onFailure: {error in
            print(error)
        })
        .disposed(by: disposeBag)
}
Return data

When the request is successful, the information of the uploaded image is returned. You can use the image URL when configuring a message.

ImageUploadResult
Name Type Description Required
infos ImageInfos The uploaded image information. O
ImageInfos
Name Type Description Required
original ImageInfo The original image information. O
ImageInfo
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

Advanced: Create a message using constructor

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).

Sample
Swift
RxSwift
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) {
        LinkApi.shared.defaultLink(templateObject:templateJsonObject) {(linkResult, error) in
            if let error = error {
                errorHandler(error)
            }
            else {
                print("defaultLink(templateObject:templateJsonObject) success.")
                
                //Do something
                guard let linkResult = linkResult else { return }
                UIApplication.shared.open(linkResult.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) {
        LinkApi.shared.rx.defaultLink(templateObject:templateJsonObject)
            .subscribe(onSuccess: { (linkResult) in
                print("success.")
                
                //Do something
                UIApplication.shared.open(linkResult.url, options: [:], completionHandler: nil)
                
            }, onFailure: {error in
                print(error)
            })
            .disposed(by: disposeBag)
    }
}

Legacy

To see how to use the Messaging API using the Legacy Kakao SDK for iOS, click this button. 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. The Legacy guide is not provided in the English version. Refer to the original Korean documentation.

See more