Currently, I am working on setting up Share Extensions in my ionic3 application.
To begin with, I followed these steps:
Firstly, I built the app and then launched it in Xcode. After that, I added a Share Extension by navigating to File -> New -> Target -> Share Extension.
Subsequently, I referred to the documentation available at this link: Share Extension in ios.
After locating the ShareViewController.swift file, I made the following modifications:
override func didSelectPost() {
if let item = self.extensionContext?.inputItems[0] as? NSExtensionItem{
for ele in item.attachments!{
let itemProvider = ele
if itemProvider.hasItemConformingToTypeIdentifier("public.jpeg"){
NSLog("itemprovider: %@", itemProvider)
itemProvider.loadItem(forTypeIdentifier: "public.jpeg", options: nil, completionHandler: { (item, error) in
var imgData: String!
if let img = item as? UIImage{
imgData = img.pngData()?.base64EncodedString(options: <#T##Data.Base64EncodingOptions#>)
}
let dict: [String : Any] = ["imgData" : imgData, "name" : self.contentText]
let userDefault = UserDefaults.standard
userDefault.set(dict, forKey: "img")
userDefault.synchronize()
})
}
}
}
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}
The Share view Controller file can be found at:
./platforms/ios/shareItems/ShareViewController.swift
My ultimate goal is to transfer the images selected from the gallery to my app and retrieve them on a specific typescript page named login.ts located at:
.src/pages/login/login.ts
I need guidance on how to create functions to accomplish this task effectively.
Your assistance will be highly appreciated.
.