How to Add iMessage Extension in Existing iOS App in Swift

This is iMessage extension app written in swift. This project demonstrates how to add iMessage extension in existing iOS App. In the project we have used static image but you can easily customize it for dynamic image from server.
Project.

You can see in below image ,how to add iMessage Extension in Existing iOS App-

Project description-

 

StickerClass: It is class used for storing image id,url and category id. you can change it according to your requirement.The following are the code of sticker class.



//
// StickerClass.swift
// SampleApp
//
// Created by https://articlemojo.com on 28/01/19.
// Copyright © 2019 https://articlemojo.com. All rights reserved.
//

import UIKit

class StickerClass: NSObject{
var stickerId:Int64!
var stickerUrl:String!
var catId:Int64!

}

Sticker Category: This class have the properties like category id, category name, active status and list of stickers. parseCategory is a function that is used to parse the category. for this example we are using local json file to manage category and image data named as sticker_data.json.



//
// StickerCategory.swift
// SampleApp
//
// Created by https://articlemojo.com on 28/01/19.
// Copyright © 2019 https://articlemojo.com. All rights reserved.
//

import UIKit

class StickerCategory: NSObject {
var catId:Int64!
var catName:String!
var isActive:Bool!
var stickerList:Array<StickerClass>?

static func parseCategory(data:Array<Any>)-> Array<StickerCategory>{
var categoryList = Array<StickerCategory>()
for case let item as Dictionary<String,Any> in data {
let category = StickerCategory()
category.catId = item["catId"] as? Int64
category.catName = item["catName"] as? String

if( item["stickerList"] as? Array<Any> != nil && (item["stickerList"] as? Array<Any>)?.count != 0){
category.stickerList = Array<StickerClass>()
for case let obj as Dictionary<String,Any> in item["stickerList"] as! Array<Any> {
let stickerObj = StickerClass()
stickerObj.catId = obj["catId"] as? Int64
stickerObj.stickerId = obj["stickerId"] as? Int64
stickerObj.stickerUrl = obj["stickerUrl"] as? String
category.stickerList?.append(stickerObj)
}
}
categoryList.append(category)
}
return categoryList
}



}

 

HomeController: We are reading data from json file and populating it to UITableView. UITableView cell hold collection and category displayed in tableview and data in collection embedded in UITableView cell.

MessagesViewController: It is subclass of MSMessagesAppViewController and main class of iMessage extension. HomeController are added as child controller in MessagesViewController.

 

Screen Shots-


0 Comment(s)

Leave a comment

Back to Top