Extensions

RSS for tag

Give users access to your app's functionality and content throughout iOS and macOS using extensions.

Posts under Extensions tag

194 Posts
Sort by:
Post not yet marked as solved
0 Answers
25 Views
In this documentation for completeRequest(returningItems:completionHandler:), there is a box shaded yellow that says: Important If the system calls your block with an expired value of true, you must immediately suspend your app extension. If you fail to do this, the system terminates your extension’s process. How does my app or my Share Extension know when the system calls the block spoken of?
Posted Last updated
.
Post not yet marked as solved
0 Answers
17 Views
Where is the “Use standard social compose interface” checkbox "in the Xcode target-adding pane" that the documentation for Share App Extension references in the "NOTE" grayed section under the "Use the Xcode Share Template"? I am sure it's not where it says it is.
Posted Last updated
.
Post not yet marked as solved
0 Answers
23 Views
We have a notification service extension which does silent login to our backing to get and update notification content. Login response comes with HTTP header Set-Cookie which adds session cookie used to identify login session. Then in the app we have actions registered for the corresponding category identifier. Both actions result in requests to our backend which also require session cookie. Both extension and the app have AppGroup entitlement and use same app group. Then we configure HTTPCookieStorage: let cookieStorage = HTTPCookieStorage.sharedCookieStorage(forGroupContainerIdentifier:<group_id>) let configuration = URLSessionConfiguration.default configuration.httpCookieStorage = NetworkClient.cookieStorage And we do use the very same configuration for all requests in extension / app, however when the app is spawned in the background after user taps one of the notification actions, the cookie storage in the app is empty. Although beforehand the cookie is set in the extension. Tested with with iOS 14.4.2. Also the question would be if it is possible to activate CFNETWORK_DIAGNOSTICS in both app and extension? App works so far. But not getting logs for the extension in the console. Appreciate any help and / or ideas.
Posted
by mneuwert.
Last updated
.
Post not yet marked as solved
1 Answers
119 Views
I'm converting a Chrome extension to work in Safari 15 using the xcrun safari-web-extension-converter. It partially works, but seems to fail with CORS permission issues in both the background script and content scripts. Oddly enough neither issue exists in Chrome. I have granted all websites permission via Safari itself after installation. In manifest.json, I have this in the permissions key: "http://*/", "https://*/" I've tried a variety of permutations, including "https://*/*" but nothing works. Every XMLHttpRequest results in the same error: Failed to load resource: Origin safari-web-extension://... is not allowed by Access-Control-Allow-Origin. Status code: 200 As mentioned, it works fine in Chrome with the same permissions. What have I missed?
Posted Last updated
.
Post not yet marked as solved
2 Answers
272 Views
I am trying to write a safari web extension that redirects users to Y URL if they type X URL without ever loading the X URL. The piece of code that I have attached below works smoothly on chrome, but not on safari. background.js function onBeforeNavigate(event) { const redirectURL = "https://google.com/" chrome.tabs.update(event.tabId, { url: redirectURL }) } chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigate,{ url: [ {urlMatches: "https://girlcodeit.com/*"}, {urlMatches: "http://girlcodeit.com/*"} ] }) manifest.json "manifest_version": 2, "name": "", "description": "", "version": "1.0", "background": { "scripts": [ "background.js" ] }, "permissions": [ "webNavigation", "tabs" ] } I have tried writing browser.tabs.update and just tabs.update in place of chrome.tabs.update in safari version, no change. I want to achieve the redirection anyhow through a safari web extension, please suggest changes in this one or share any other approaches. webRequestBlocking is not supported by Safari, so that doesn't work either.
Posted
by mt2107.
Last updated
.
Post not yet marked as solved
1 Answers
52 Views
So I've been trying to debug / read console.logs from background scripts when using manifest v3 but it never fires any log. It works well in manifest v2 though. I have set the persmission and host_permission as well changed my background to service_work in manifest but nothing really happens: "background": { "service_worker": "scripts/background.js" }, My Qyestion is, is it currently possible to use manifest v3 on iOS safari web extension? Some Notes: Reading this page: https://developer.apple.com/documentation/safariservices/safari_web_extensions/assessing_your_safari_web_extension_s_browser_compatibility It says: "background: In iOS, you must set the persistent attribute to false. With manifest version 3, all background pages are nonpersistent." So I'm guessing it is somehow possible to use right?
Posted
by Dannark.
Last updated
.
Post not yet marked as solved
0 Answers
34 Views
INIntent Issue In my main app, after I send a message(key code): let inImage = INImage(imageData: imageData) let person = INPerson( personHandle: INPersonHandle( value: personId, type: .emailAddress), nameComponents: nil, displayName: personName, image: inImage, contactIdentifier: nil, customIdentifier: String(chatid) ) let smi = INSendMessageIntent( recipients: persons, outgoingMessageType: .outgoingMessageText, content: nil, speakableGroupName: groupName, conversationIdentifier: "\(chatid)", serviceName: nil, sender: nil, attachments: nil ) smi.setImage(inImage, forParameterNamed: \.speakableGroupName) let interaction = INInteraction(intent: smi, response: nil) interaction.groupIdentifier = String(chatid) interaction.donate { error in } I get INImage instance in share extension by: if let intent = extensionContext?.intent as? INSendMessageIntent, let avatar = intent.keyImage() { // ... } When I call INImage.fetchUIImage method: func loadImageBy(_ inImage: INImage) { imgView.image = nil loadImageIdentifier = UUID() inImage.fetchUIImage { [weak self, loadImageIdentifier] image in guard self?.loadImageIdentifier == loadImageIdentifier else { return } self?.imgView.image = image } } I got this error: Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[INRemoteImageProxy fetchUIImageWithCompletion:]: unrecognized selector sent to instance 0x2810969e0’
Posted
by lcrystal.
Last updated
.
Post not yet marked as solved
1 Answers
414 Views
I am trying to install pods into AppExtension target with target 'NotificationService' do     pod 'CleverTap-iOS-SDK', '~> 3.10.0', :modular_headers => true end This pods are also added to my main app target and working fine. But when I try to install same pods to Notification Service extension, I am running into Unity library related error (90 error of same kind for libiPhone-lib.a). Undefined symbols for architecture arm64:   "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::imbue(std::__1::locale const&)", referenced from:       vtable for std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libiPhone-lib.a(CrashReporter.o)   "std::__1::basic_streambuf<char, std::__1::char_traits<char> >::setbuf(char*, long)", referenced from:       vtable for std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> > in libiPhone-lib.a(CrashReporter.o) These errors are not coming if I add same pods to main Target. Also, Unity is not installed on any Extension, just on main Target. I wonder if I have to add/remove any library or header paths from extension by which it doesn't consider Unity inside extension project. Screenshots of settings attached for reference.
Posted Last updated
.
Post not yet marked as solved
2 Answers
112 Views
I'm trying to understand what exactly is made possible by Media Device Discovery Extensions, what responsibility the containing app has, and what exactly is made available to other apps or the system, if anything. I haven't been able to find any meaningful high level documentation, and WWDC 2022 session 10096 only mentions these new extensions in passing. The most comprehensive body of information I found is the example project: https://developer.apple.com/documentation/devicediscoveryextension/discovering_a_third-party_media-streaming_device?changes=latest_beta&language=objc However, I don't think it's working the way it should out of the box: I've got the Client target app built and running on an iPad Pro running iPadOS 16 Beta 2 I've got the MacServer target running on a Mac Mini with macOS 13 Ventura Beta 2 I've got the Server target running on an iPhone with iOS 15.5. (Non-beta) If I tap the AirPlay icon on the Client's video player, I can see the two servers, but selecting one just causes a spinner to show up next to its name. This keeps going for a while, eventually the spinner goes away again, but the device selection tick stays next to 'iPad'. The text "Select route" also doesn't change, which I think it's supposed to, judging by the code. I've tried a variety of combinations of settings on the servers - bluetooth only, bonjour only, different protocols, etc., but I'm always getting the same behaviour. Has anyone had any success in getting the example to work, and how? Is there any high level documentation available that I've missed? Can someone explain what exactly we can build with this in more detail than "implementations of custom A/V streaming protocols?" The WWDC session video talks about 3rd party SDKs, so do these extensions have to be embedded in every app that would be streaming the video, implying that it's not useful for mirroring?
Posted
by pmdj.
Last updated
.
Post not yet marked as solved
1 Answers
56 Views
Hi there, We're developing an extension that have the minimum target version 14.0 and it's embedded to an application that have the minimum target version of 11.0 and we want to know what will be the behavior when we have that mismatch of minimal versions between Extension and the app that the extension is embedded to. Our main questions are: Taking in consideration that we are able to build/upload to the store the app with those different target mismatches (let me know if this not gonna happen please) we can think that: It's a common thing to have different versions for each target Customers with iOS version < 14.0 will not be able to use the benefits of the extension but nothing changes for them Customers with iOS version > 14.0 will be able to use the feature introduced by the extension Thanks in advance!
Posted
by renatomdg.
Last updated
.
Post not yet marked as solved
0 Answers
47 Views
I am trying to record and play audio from keyboard extension in Swift, but it throws an error on line recordingSession.setActive(true) Error: failed to record The operation couldn’t be completed. (OSStatus error 561015905.) I have already set the key RequestsOpenAccess to true in info.plist and granted full access to the keyboard extension.
Posted Last updated
.
Post not yet marked as solved
0 Answers
45 Views
I'm trying to use Network Extension to develop a VPN tool for iOS devices. I used a NETunnelProviderManager to create VPN configuration and created extension target conaining a subclass of NEPacketTunnelProvider. But when I use NETunnelProviderManager.connection.startVPNTunnel() to enable the extension, I got a error output: "Failed to fetch info with type 2: Connection interrupted". I checked my entitlements for both app and extension and they both contains PacketTunnel capability. And the info.plist for extension is correct with a principal class $(PRODUCT_MODULE_NAME).PacketTunnelProvider (which is identical to my provider class). I want to know which configuration could cause the problem and how can I fix it. Thank for any helping.
Posted
by yh0x13f.
Last updated
.
Post not yet marked as solved
0 Answers
78 Views
I'm developing iOS message extension to filter the unwanted message. The plugin needs a help from server to filter the message. However, the iOS returned the error NSURLErrorDomain while requesting the server. Based on the official document, I defined the key/value pair in Info.plist of Message Extension. ILMessageFilterExtensionNetworkURL has value: https://mydomain.io/api/v1/sms The code that I test the request as follows: let url = URL(string: "https://mydomain.io/api/v1/sms")! var request = URLRequest(url: url) request.setValue("application/json", forHTTPHeaderField: "Content-Type") request.setValue("you-value-goes-here", forHTTPHeaderField: "X-API-KEY") let task = URLSession.shared.dataTask(with: request) { data, _, error in if let data = data { print(data) } else if let error = error { print("Http failed: \(error)") } } task.resume() From the stack trace, as far as I known, there is a problem with dns resolution. Why does this happened and how to fix this case? [0] (null) "_kCFStreamErrorCodeKey" : Int32(-72000) [1] (null) "NSUnderlyingError" : domain: "kCFErrorDomainCFNetwork" - code: 18446744073709550613 [2] (null) "_NSURLErrorFailingURLSessionTaskErrorKey" : "LocalDataTask <B496A974-7009-4FCE-BF45-FEC07BA1E8DF>.<1>" [3] (null) "_NSURLErrorRelatedURLSessionTaskErrorKey" : 1 element [4] (null) "NSLocalizedDescription" : "A server with the specified hostname could not be found." Thanks
Posted
by ntk19.
Last updated
.
Post not yet marked as solved
1 Answers
196 Views
I want to localize two value in info.plist. First one is [ NSFileProviderDecorations - Item0 - Label ], and second one is [ NSExtensionFileProviderActionName ]. I could localize first one using InfoPlist.strings. (and Label-NSStringFormat) But it does not work for second one. I tried InfoPlist.strings, Localizable.strings, ..., but i can't localize this key. What should i do?
Posted
by eunjo.
Last updated
.
Post not yet marked as solved
3 Answers
400 Views
I am sharing my CoreData model between my iOS main app target and a new Share Extension target like this post:  This is working well for the most part except for one thing.  NSFetchedResultsController is not returning results when called from the Shared Extension. What is strange though is that if I do a plain NSFetchRequest in my Share Extension, I do get CoreData results returned that were originally saved from the main app...so I think Container setup as well as model must be being shared correctly via AppContainer. NSFetchedResultsControllerDelegate controllerDidChangeContent is never called. Any ideas or suggestions? import UIKit import MobileCoreServices class ShareViewController: UIViewController { private(set) lazy var resultsController: NSFetchedResultsController<Person> = createFetchedResultsController() override func viewDidLoad() { super.viewDidLoad() let fetchRequest = NSFetchRequest<Person>(entityName: "Person") fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)] do { /// this works! let persons = try CoreDataManager.shared.managedObjectContext.fetch(fetchRequest) print("Got \(persons.count) Persons") } catch { print("Fetch failed") } activateResultsController() } func createFetchedResultsController() -> NSFetchedResultsController<Person> { CoreDataManager.shared.container.viewContext.stalenessInterval = 0 CoreDataManager.shared.container.viewContext.refreshAllObjects() CoreDataManager.shared.container.viewContext.stalenessInterval = -1 let fetchRequest = NSFetchRequest<Person>(entityName: "Person") fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)] ////managedObjectContext: CoreDataManager.shared.managedObjectContext, let controller = NSFetchedResultsController( fetchRequest: fetchRequest, managedObjectContext: CoreDataManager.shared.managedObjectContext, sectionNameKeyPath: nil, cacheName: nil ) controller.delegate = self return controller } private func activateResultsController() { do { try resultsController.performFetch() } catch { fatalError("Failed to fetch entities: \(error)") } } } // MARK: - Results Controller Delegate extension ShareViewController: NSFetchedResultsControllerDelegate { func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) { guard let sections = resultsController.sections else { return } let section = sections[0] let rows = section.numberOfObjects print("rows=\(rows)") } } import UIKit import CoreData class CoreDataManager { static let shared = CoreDataManager() internal var container: NSPersistentContainer var managedObjectContext: NSManagedObjectContext { container.viewContext } init() { container = NSPersistentContainer(name: Constants.name) guard let storeDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first else { // We'll throw a fatalError() because we can't really proceed without storeDirectory fatalError(file: "Could not find .applicationSupportDirectory - exiting") } let storeURL = storeURL(for: "group.mygroup.testshareextensioncoredata", databaseName: "\(Constants.name)") let storeDescription = NSPersistentStoreDescription(url: storeURL) container.persistentStoreDescriptions = [storeDescription] container.loadPersistentStores(completionHandler: { storeDescription, error in if let error = error as NSError? { // We'll throw a fatalError() because we can't really proceed without loading the PersistentStore fatalError("loadPersistentStore failed \(error), \(error.userInfo)") } }) } // MARK: - Core Data Saving support func saveContext() { managedObjectContext.performAndWait { if managedObjectContext.hasChanges { do { try managedObjectContext.save() } catch { } } } } /// Returns a URL for the given app group and database pointing to the sqlite database. func storeURL(for appGroup: String, databaseName: String) -> URL { guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup) else { fatalError("Shared file container could not be created.") } return fileContainer.appendingPathComponent("\(databaseName).sqlite") } } internal extension CoreDataManager { enum Constants { static let name = "ShareExtensionCoreDataTest" } }
Posted
by tanzy_m.
Last updated
.
Post not yet marked as solved
3 Answers
326 Views
In MacOS I can achieve this via func sendKeyStrike(_ keyCode: CGKeyCode, useCommandFlag: Bool) { let sourceRef = CGEventSource(stateID: .combinedSessionState) if sourceRef == nil { NSLog("FakeKey: No event source") return } let keyDownEvent = CGEvent(keyboardEventSource: sourceRef, virtualKey: keyCode, keyDown: true) if useCommandFlag { keyDownEvent?.flags = .maskCommand } let keyUpEvent = CGEvent(keyboardEventSource: sourceRef, virtualKey: keyCode, keyDown: false) keyDownEvent?.post(tap: .cghidEventTap) keyUpEvent?.post(tap: .cghidEventTap) } Is there a function call either in XCUITest or any other framework to achieve keyboard strokes in IOS? IOS Seems to have HID keycodes but I just can't find a way to send them to the device. Either through XCUITest or any other framework. (I am ok with simulating a HID device using python or something else to command my iOS device as well.
Posted Last updated
.
Post not yet marked as solved
3 Answers
233 Views
I've configured an item and placeholder in NSFileProviderExtension iOS extension, and an XPC service in the provider (based on the template for XPC service for Mac, but as part of the NSFileProviderExtension When connecting to the service from the app using code example in getFileProviderServicesForItem I am getting an error straight in the completion handler of that function: Error Domain=NSCocoaErrorDomain Code=4097 "Error while sending identifierForItemAtURL:completionHandler:" UserInfo={NSDebugDescription=Error while sending identifierForItemAtURL:completionHandler:, NSUnderlyingError=0x2833640c0 {Error Domain=NSCocoaErrorDomain Code=4097 "connection from pid 30324 on anonymousListener or serviceListener" UserInfo={NSDebugDescription=connection from pid 30324 on anonymousListener or serviceListener}}} Could you maybe suggest what I am missing? Or, is there an example somewhere of the FileProvider extension with the service being called from the app? Code: File Provider service definition: https://github.com/simplex-chat/simplex-chat/blob/af3dcc4a9a9b24751bf9d74af67cf8e7d119597a/apps/ios/SimpleX%20Service/SimpleXFPService.swift Application code that calls the service: https://github.com/simplex-chat/simplex-chat/blob/af3dcc4a9a9b24751bf9d74af67cf8e7d119597a/apps/ios/Shared/FPService.swift Thank you!
Posted Last updated
.