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

Message

Kakao Talk Sharing: iOS

This document describes how to integrate Kakao Talk Sharing APIs into your service with the Kakao SDK for iOS ("iOS SDK").

Before you begin

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.

1. Select a type of Messaging API

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

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 How to use 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 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}

Configure a message

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.

Feed
List
Location
Commerce
Text
Calendar
let title = "Feed message"
let description = "Example of Feed message"

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 message"

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 message"
let description = "Example of Location message"

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 message"
let description = "Example of Commerce message"

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.

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.

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.

3. Request to send a message

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.

Send message with default template

Basic information
Reference App setting
[SDK, RxSDK] shareDefault()
[SDK] isKakaoTalkSharingAvailable()
[SDK] makeDefaultUrl()
[SDK] SharingResult
Install
Import modules
Initialize
Permission Prerequisite Kakao Login User consent
- Register platforms - -

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.

Request

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.

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.

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.

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

Send message with custom template

Basic information
Reference App setting
[SDK, RxSDK] shareCustom()
[SDK] isKakaoTalkSharingAvailable()
[SDK] makeCustomUrl()
[SDK] SharingResult
Install
Import modules
Initialize
Permission Prerequisite Kakao Login User consent
- Register platforms
Message Template
- -

This API enables you to customize a template in [Tools] > [Message Template Builder] and send a message through Kakao Talk.

Request

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.

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.

Sample

Swift
RxSwift
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)

Send scrape message with default template

Basic information
Reference App setting
[SDK, RxSDK] shareScrap()
[SDK] isKakaoTalkSharingAvailable()
[SDK] makeScrapUrl()
[SDK] SharingResult
Install
Import modules
Initialize
Permission Prerequisite Kakao Login User consent
- Register platforms - -

This API scrapes a web page, configures a message based on the scraped web page information, and then sends it through Kakao Talk.

Request

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.

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.

Sample

Swift
RxSwift
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)

Send scrape message with custom template

Basic information
Reference App setting
[SDK, RxSDK] shareScrap()
[SDK] isKakaoTalkSharingAvailable()
[SDK] makeScrapUrl()
[SDK] SharingResult
Install
Import modules
Initialize
Permission Prerequisite Kakao Login User consent
- Register platforms
Message Template
- -

This API scrapes 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 scrape message.

Request

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.

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.

Sample

Swift
RxSwift
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)

Set Kakao Talk Sharing success callback

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:

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

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. You cannot use the system reserved words CHAT_TYPE, HASH_CHAT_ID and TEMPLATE_ID as keys for the serverCallbackArgs. The key is included in the notification with the value defined in the specification of Kakao Talk Sharing success callback.

Here is a code snippet showing how to set parameters for Kakao Talk Sharing 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 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.

Upload image

Basic information
Reference App setting
[SDK, RxSDK] imageUpload()
[SDK, RxSDK] imageScrap()
[SDK] ImageUploadResult
Install
Import modules
Initialize
Permission Prerequisite Kakao Login User consent
- Register platforms - -

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 server or scrape it. You can only upload an image with a file size of 5 MB or less. The images uploaded to the Kakao server are stored for up to 100 days and automatically deleted after the period.

Sample

Upload image
Swift
RxSwift
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)
}
Scrape image
Swift
RxSwift
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)
}

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) {
        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)
    }
}

See more