Open ShortCut file pragmatically - ios

I have shortcut file was added as a file in my Xcode project and I need that open this file from my app programmatically.
I try with UIApplication.shared.open but the file not open.
if let url = Bundle.main.url(forResource: "saverone", withExtension: "shortcut", subdirectory:"") {
UIApplication.shared.open(url.absoluteString, completionHandler: { (success) in
print("Settings opened: \(success)") // Prints true
})
}
I edit the plist file:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>shortcuts</string>
<string>file</string>
<string>file:///private/var/containers/Bundle/Application/45D0D372-725B-43A2-9C32-AE9403AD88FF/Saverone.app/</string>
<string>Saverone.app/</string>
<string>saverone.shortcut</string>
<string>shortcuts://</string>
<string>file:///private/var/containers/Bundle/Application/111111-725B-43A2-9C32-AE9403AD88FF/Saverone.app/saverone.shortcut</string>
<string>private/var/containers/Bundle/Application/111111-5E8E-4695-845D-D55AD6526673/Saverone.app/saverone.shortcut</string>
</array>
it is possible ?

Related

App's created Folders/Files don't show up in "Files" on iPhone

wonder if anyone can help me. I have an app and I'm trying to move some files into iCloud so they'll show up in "Files" and cloud to other devices. I've been going through lots of resources online researching what's wrong, and nothing seems to help.
In my app project, I have turned on iCloud Documents in capabilities.
In my plist file, I have this:
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.com.mypublishername.myappname</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>myappname</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
In my entitlements file I have:
<dict>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.com.mypublishername.myappname</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>iCloud.com.mypublishername.myappname</string>
</array>
</dict>
in ObjC, I'm fetching the iCloud folder like so:
NSURL *rootDirectory = [[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]URLByAppendingPathComponent:#"Documents"];
if (rootDirectory)
{
if (![[NSFileManager defaultManager] fileExistsAtPath:rootDirectory.path isDirectory:nil]) [[NSFileManager defaultManager] createDirectoryAtURL:rootDirectory withIntermediateDirectories:YES attributes:nil error:nil];
gCloudFolder=rootDirectory;
}
Then, when I save a file, I do so locally, and move it into the cloud folder like this:
//
// theFilename is a file in the app's documents folder...
//
int aFile=creat(theFilename,S_IREAD|S_IWRITE);close(aFile);
aFile=open(theFilename,O_BINARY|O_RDWR);
if (aFile)
{
write(aFile,theDataPtr,theLen);
close(aFile);
if (gCloudFolder)
{
NSURL *aLocalStr=[NSURL fileURLWithPath:[NSString stringWithUTF8String:theFilename]];
NSURL *aCloudStr=[gCloudFolder URLByAppendingPathComponent:#"testing_file.txt"];
NSError *error;
if (![[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:aLocalStr destinationURL:aCloudStr error:&error]) NSLog(#"iCloud Error occurred: %#", error);
}
So... what happens. This file DOES get created. If I run this twice, it tells me it can't move to testing_file.txt because it already exists. Also, if I try to setUbiquitous:NO on the file, it tells me I can't set it to no when the file hasn't been synced.
Any idea why my app's folder and this file don't show up in my FILES folder under iCloud?
I have increased the bundle version, which is something I've seen elsewhere. Did nothing.
What am I doing wrong?
This completely stunned me; I had no idea it was possible. I'll just describe my test app in full. It's going to look a lot like yours!
Here is the bundle identifier:
Here is the entitlement:
Here is the entitlement text:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.com.neuburg.matt.SaveIntoFilesApp</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>iCloud.com.neuburg.matt.SaveIntoFilesApp</string>
</array>
</dict>
</plist>
Here is the entry in the Info.plist:
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.com.neuburg.matt.SaveIntoFilesApp</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>MyApp</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
Here is the app delegate:
var ubiq : URL!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DispatchQueue.global(qos:.default).async {
let fm = FileManager.default
let ubiq = fm.url(forUbiquityContainerIdentifier:nil)
print("ubiq: \(ubiq as Any)")
DispatchQueue.main.async {
self.ubiq = ubiq
}
}
return true
}
Here is the button I tap:
#IBAction func doButton (_ sender:Any) {
if let del = UIApplication.shared.delegate as? AppDelegate {
if let ubiq = del.ubiq {
do {
let fm = FileManager.default
let docs = ubiq.appendingPathComponent("Documents")
try? fm.createDirectory(at: docs, withIntermediateDirectories: false, attributes: nil)
let url = docs.appendingPathComponent("test.txt")
print("here we go")
try? fm.removeItem(at: url)
try "howdy \(Date())".write(to: url, atomically: true, encoding: .utf8)
print("saved")
} catch {
print(error)
}
}
}
}
I did have to increment the bundle version (from 1 to 2) and I did have to kill and restart the Files app. And then I saw my file (and can open and examine it):

Sharing attachments from Mail App not working in iOS 13

I'm working on the app that has share extension.
Share attachment from Mail App with Share extension is not working.
But sharing attachments(pdf, doc, image etc.) from gmail app working fine.
My swift code
for attachment in contents{
if attachment.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
attachment.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil) { data, error in
//Do action for image
}
} else {
if let item = (filePicker!.types as [String]).first(where: { (item) -> Bool in attachment.hasItemConformingToTypeIdentifier(item)}){
attachment.loadItem(forTypeIdentifier: item, options: nil) { data, error in
//Do action for file
}
}
}
}
My NSExtensionActivationRule:
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsAttachmentsWithMaxCount</key>
<integer>1</integer>
</dict>
I never work with the sharing extensions before, so any knowledge that can be shared will be a great resource for me.
Thanks in advance!

How to get a iOS share extension to get web page content from Safari instead of URL

I have a working share extension written in swift. When I test a share operation from Safari, I always only get the URL type (kUTTypeURL).
What I want is to get some form of rendered version of what the user is looking at (PDF or HTML?). Using the URL and opening it in a webview is not workable due to authentication issues, etc.
I've tried many different activation rules with no change. Here is the current one I am using:
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>20</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
My controller looks like this - when run from Safari, it always only has one attachment type - the URL:
override func didSelectPost() {
if let item = extensionContext?.inputItems.first as? NSExtensionItem {
if let attachments = item.attachments {
for attachment: NSItemProvider in attachments {
if attachment.hasItemConformingToTypeIdentifier(kUTTypePropertyList as String) {
attachment.loadItem(forTypeIdentifier: kUTTypePropertyList as String, options: nil, completionHandler: { (data, error) in
// Do stuff with this content now
self.extensionContext?.completeRequest(returningItems: [], completionHandler:nil)
})
}
if attachment.hasItemConformingToTypeIdentifier(kUTTypeURL as String) {
attachment.loadItem(forTypeIdentifier: kUTTypeURL as String, options: nil, completionHandler: { (url, error) in
if let shareURL = url as? NSURL {
// Do stuff with your URL now.
}
self.extensionContext?.completeRequest(returningItems: [], completionHandler:nil)
})
}
}
}
}
}
Other approaches I've seen use a javascript file to walk the DOM but have seen no good examples and I'm not clear on if this would help me in any case.
The key is in using this line in your info.plist file:
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionJavaScriptPreprocessingFile</key>
<string>Action</string>
<key>NSExtensionActivationRule</key>
...your should be fine...
</dict>
At NSExtensionJavaScriptPreprocessingFile you specify the name of the .js file that contains javascript file that must contain a global object named ExtensionPreprocessingJS. You should then search for the items conforming to kUTTypePropertyList in your code (and it seems that you do already that looking at your code).
This is a short list of what you should do, ask if you need something more and it is easy to find more data on the internet if you start from this too.

TIC SSL Trust Error while trying to read a txt file

I'm having this problem with reading from a txt file from a website without a certificate even though I have allowed it in Info.plist.
My Swift code looks like this:
let url = URL(string: "http://newskit.matsworld.io/domaci/text.txt")!
let task = URLSession.shared.downloadTask(with: url) { localURL, urlResponse, error in
if let localURL = localURL {
if let string = try? String(contentsOf: localURL) {
print(string)
}
}
}
task.resume()
And the Info.plist looks like this:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>http://newskit.matsworld.io</key>
<dict>
<key>ExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>IncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
I'm stuck with this and can't figure it out. Thanks for help!
The domain key is supposed to be just the domain without the scheme (http) and without subdomains if IncludesSubdomains is specified
<key>matsworld.io</key>

FBAuth not working Swift

I'm trying to add authentication via Facebook onto my app, within my plist I have:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb146156719258538</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>146156719258538</string>
<key>FacebookDisplayName</key>
<string>applicationTest</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
In my AppDelegate I have a method:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let appId = FBSDKSettings.appID()
print("app id:" + appId!)
print("url id:" + String(url.scheme!.hasPrefix("fb\(appId)")))
print("url host:" + String(describing: url.host))
if url.scheme != nil && url.scheme!.hasPrefix("fb\(appId)") && url.host == "authorize" { // facebook
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
}
return false
}
When the FB login button is clicked in my ViewController, you would then expect the code within the IF statement of the AppDelegate method to be executed. However this returns false, i've debugged the code and it appears that the line:
url.scheme!.hasPrefix("fb\(appId)")
Is returning false even though the correct appId is being printed.
Does anyone know why this is happening?
P.S: Printing the url.scheme gives:
fb146156719258538
Have you configured the settings on your Facebook account correctly?

Resources