i am working on content blocker and block the adult site so, this code is perfect work on simulator when i test on iPhone 6 then its no one site is block
Alamofire.request(url).responseJSON { response in
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
print("Data: \(utf8Text)")
self.containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.domainName.contentBlocker")
let path = self.containerURL?.appendingPathComponent("blockerList.json")
self.text = utf8Text.description
do {
try self.text.write(to: path!, atomically: true, encoding: String.Encoding.utf8)
}catch{
print(error)
}
print(path)
}
}
Then after load data on extension handler file. Thanks in advance.
To launch a Simulator without running an appChoose Xcode > Open Developer Tool > Simulator. Control-click the Xcode icon in the Dock, and from the shortcut menu, choose Open Developer Tool > Simulator.
Select a simulated device For iOS, tvOS, and watchOS apps, you can choose a simulated device, under [Platform] Simulators, from the run destination menu next to the scheme menu in the toolbar.
I had a similar issue where reading the contents of the group directly worked on the simulator, but not on a device. It resolved this by creating a subdirectory in the group and do all reading writing in this subdirectory.
if let root = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "YOUR_GROUP_NAME") {
let url = root.appendingPathComponent("storage")
try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
let fileCoordinator = NSFileCoordinator()
var error: NSError?
fileCoordinator.coordinate(readingItemAt: url, options: .withoutChanges, error: &error) { url in
if let urls = try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: [.canonicalPathKey], options: []) {
for u in urls {
print("\(u.standardizedFileURL)")
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With