Post

Replies

Boosts

Views

Activity

Read file with System Network Extension from App Group
I have trouble with reading a file from an App Group with my System Network Extension. The app group container is found successfully. However the file read returns empty. In the app itself the same code runs fine and returns a string array of items found in the file. Code: func readFile() - [String] {         var jsonResult: [String] = []         guard let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: AppConstants.groupID) else {             fatalError()         }         let fileURL = containerURL.appendingPathComponent("file.json")         if let data = try? NSData(contentsOfFile: fileURL.path, options: .mappedIfSafe) as Data {             if let json = try? JSONSerialization.jsonObject(with: data, options: .fragmentsAllowed) {                 jsonResult = json as! [String]             }         }         os_log("jsonResult: %{public}@", jsonResult)         return jsonResult     } Log: default 09:42:19.486793+0200 app-network-extension container_create_or_lookup_app_group_path_by_app_group_ identifier: success default 09:42:20.105792+0200 app-network-extension jsonResult: ( ) Edit, after more digging: fileURL is different! App: file:///Users/me/Library/Group%20Containers/ SysExt: file:///private/var/root/Library/Group%20Containers/
2
0
1.1k
May ’21
NSBackgroundActivityScheduler running too soon
I have an array of activities that need to be run at a specific time. The run in a background helper app. The array is sorted on date/time. At 12:08:51 I add a new item in the array.. to run at 12:12. Upon creation the array is sorted again and the closest is added as an activity to a NSBackgroundActivityScheduler. However it runs at creation and a few times more before 12:12. The next automation Normal doesn't run at creation as activity (activity Normal is already in the array of activities). Why is this happening? And how can I fix it? Log: 12:12:15.664819+0200 Next Automation Normal on 2021-04-15 08:50:00 +0000 Code: }
1
0
1.1k
Apr ’21
Bundle not found in embedded Helper app in Main app
I have a Swift Package with shared code. With Xcode's SPM added to my Xcode project. Works great in the main app. Doesn't work in the helper app when exported. Running the helper app in Xcode itself works fine. But when running as an exported and signed app it doesn't work. This error message was found in console: Fatal error: unable to find bundle named MySwiftPackageName: file MySwiftPackageName/resource_bundle_accessor.swift, line 27 I double checked, the package is really added at Build Phase - Link Binary With Libraries When I inspect the exported main app and helper app I found the package in the main resources folder but not in the helper app resources folder. How can I fix this?
0
0
927
Mar ’21
Context Menu tvOS SwiftUI
.contextMenu {} is not working for me in my tvOS app. It is supported in tvOS 14 https://developer.apple.com/documentation/swiftui/view/contextmenu(menuitems:) Someone an idea how to get it working? Example import SwiftUI struct NumberItem: Identifiable, Hashable {     var id = UUID()     var number: String } struct ContentView: View {     let array: [NumberItem] = [NumberItem(number: "423"),                                NumberItem(number: "645"),                                NumberItem(number: "213"),                                NumberItem(number: "975"),                                NumberItem(number: "357"),                                NumberItem(number: "950"),                                NumberItem(number: "043"),                                NumberItem(number: "174")]     let columns = [GridItem(.adaptive(minimum: 300.0, maximum: 800.0))]     var body: some View {         ScrollView {             LazyVGrid(columns: columns, spacing: 20) {                 ForEach(array, id: \.id) { item in                     ItemView(item: item)                         .contentShape(RoundedRectangle(cornerRadius: 12, style: .continuous))                         .contextMenu {                             // Edit                             Button(action: {                                 print("Edit")                             }) {                                 Text("Edit")                                 Image(systemName: "square.and.pencil")                             }                             // Delete                             Button(action: {                                 print("Delete")                             }) {                                 Text("Delete")                                 Image(systemName: "trash")                             }                         }                 }             }         }     } } struct ItemView: View {     @State private var focused: Bool = false     @State var item: NumberItem     var body: some View {         Group {             Text("Item \(item.number)")                 .padding()         }         .padding()         .background(Color.pink)         .cornerRadius(12)         .scaleEffect(self.focused ? 1.20 : 1.00)         .shadow(radius: 10)         .focusable(true) { isFocused in             withAnimation(.easeInOut(duration:0.3)) {                 self.focused = isFocused             }         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } } Full project: https://github.com/l1ghthouse/TVContextMenu
0
1
1.6k
Sep ’20
SwiftUI and dynamic NSSortDescriptors in @FetchRequest
I have a list with items that contain a title and a date. User can set what to sort on (title or date). However I can't figure out how to change the NSSortDescriptor dynamically. import SwiftUI import CoreData struct ContentView: View { @Environment(\.managedObjectContext) private var viewContext @FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Test.title, ascending: true)], animation: .default) private var items: FetchedResults<Test> @State private var sortType: Int = 0 @State private var sortDescriptor: NSSortDescriptor = NSSortDescriptor(keyPath: \Test.title, ascending: true) var body: some View { Picker(selection: $sortType, label: Text("Sort")) { Text("Title").tag(0) Text("Date").tag(1) } .pickerStyle(SegmentedPickerStyle()) .onChange(of: sortType) { value in sortType = value if sortType == 0 { sortDescriptor = NSSortDescriptor(keyPath: \Test.title, ascending: true) } else { sortDescriptor = NSSortDescriptor(keyPath: \Test.date, ascending: true) } } List { ForEach(items) { item in let dateString = itemFormatter.string(from: item.date!) HStack { Text(item.title!) Spacer() Text(dateString) } } } .onAppear(perform: { if items.isEmpty { let newEntry1 = Test(context: self.viewContext) newEntry1.title = "Apple" newEntry1.date = Date(timeIntervalSince1970: 197200800) let newEntry2 = Test(context: self.viewContext) newEntry2.title = "Microsoft" newEntry2.date = Date(timeIntervalSince1970: 168429600) let newEntry3 = Test(context: self.viewContext) newEntry3.title = "Google" newEntry3.date = Date(timeIntervalSince1970: 904903200) let newEntry4 = Test(context: self.viewContext) newEntry4.title = "Amazon" newEntry4.date = Date(timeIntervalSince1970: 773402400) if self.viewContext.hasChanges { try? self.viewContext.save() } } }) } } private let itemFormatter: DateFormatter = { let formatter = DateFormatter() formatter.dateStyle = .short formatter.timeStyle = .none return formatter }() When I change @FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Test.title, ascending: true)], animation: .default) private var items: FetchedResults<Test> to @FetchRequest(sortDescriptors: [sortDescriptor], animation: .default) private var items: FetchedResults<Test> the error "Cannot use instance member 'sortDescriptor' within property initializer; property initializers run before 'self' is available" appears. I also tried to store the NSSortDescriptor in a UserDefault and create an init that creates it's own FetchRequest.. still no dynamic sorting... Anyone a pointer where to look to solve this problem? Whole project found here: https://github.com/l1ghthouse/FRDSD
1
0
4.4k
Sep ’20
Sign up for trusted partner Apple Maps Guides
"Apple Maps editors have worked with trusted brands and partners to offer Guides for great places around the world to eat, shop, and explore. >>> Guides in Maps will be available for cities including San Francisco, New York, London, and Los Angeles." How can you sign up as a trusted partner for Apple Maps Guides? And could that also be for other cities... or only those mentioned?
0
0
876
Jun ’20