I am trying to use crosswalk to make my web app into iOS app
and I following the steps of Quickstart in this page https://github.com/crosswalk-project/crosswalk-ios
but I keep facing the problem:
in the ViewController.swift
When I import XWalkView, It always appears that It can't find the XWalkView module which makes me stop from my development...
Somebody help me.
Here's the code of ViewController.swift:
import UIKit
import WebKit
import XWalkView
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var start_url = "index.html"
var xwalk_extensions = ["Extension.load"]
if let plistPath = NSBundle.mainBundle().pathForResource("manifest", ofType: "plist") {
if let manifest = NSDictionary(contentsOfFile: plistPath) {
start_url = manifest["start_url"] as? String ?? start_url
xwalk_extensions = manifest["xwalk_extensions"] as? [String] ?? xwalk_extensions
}
}
let webview = WKWebView(frame: view.frame, configuration: WKWebViewConfiguration())
webview.scrollView.bounces = false
view.addSubview(webview)
for name in xwalk_extensions {
if let ext: AnyObject = XWalkExtensionFactory.createExtension(name) {
webview.loadExtension(ext, namespace: name)
}
}
if let root = NSBundle.mainBundle().resourceURL?.URLByAppendingPathComponent("www") {
var error: NSError?
let url = root.URLByAppendingPathComponent(start_url)
if url.checkResourceIsReachableAndReturnError(&error) {
webview.loadFileURL(url, allowingReadAccessToURL: root)
} else {
webview.loadHTMLString(error!.description, baseURL: nil)
}
}
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
perhaps you forget to link the XWalkView.framework in your app target?
Try this step:
Open Xcode, select your app project, in 'General' -> 'Linked Frameworks and Libraries', select '+', choose 'XWalkView.framework' to add it into the linking frameworks. Then shot another build. It's ok if the XWalkView.framework turns red.
Related
I'm working on a project where I have to download a USDZ file from a URL, preconfigured with white materials, then customize it in runtime and finally view it in AR with ARQuickLook.
At the moment, I thought the best way was to download the asset using the ModelEntity download method, change its properties and then show it with the ARQuickLook preview.
Currently, I am completely stuck in the last step where I am looking for the way to pass the modified model entity to the ARQuickLook preview controller, but it only accepts a URL and no other data types.
A simple code example below:
var modelURL: URL?
override func viewDidLoad() {
super.viewDidLoad()
self.downloadUSDZ()
}
#IBAction func arQuickLookButtonPressed(_ sender: Any) {
guard modelURL != nil else { return }
let previewController = QLPreviewController()
previewController.dataSource = self
present(previewController, animated: true, completion: nil)
}
func downloadUSDZ() {
modelURL = URL(string: "https://developer.apple.com/augmented-reality/quick-look/models/drummertoy/toy_drummer.usdz")!
guard let entity = try? ModelEntity.loadModel(contentsOf: modelURL!) else {
print("Entity download failed")
return
}
for child in entity.children {
var newMaterial = SimpleMaterial()
newMaterial.color.tint = UIColor.cyan
child.model?.materials = [newMaterial]
}
}
func numberOfPreviewItems(in controller: QLPreviewController) -> Int { return 1 }
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
let previewItem = ARQuickLookPreviewItem(fileAt: modelURL!) //<---- HERE I NEED TO DISPLAY THE MODIFIED MODEL ENTITY
previewItem.canonicalWebPageURL = URL(string: "https://developer.apple.com/augmented-reality/quick-look/models/drummertoy/")
previewItem.allowsContentScaling = false
return previewItem
}
Can anyone give me some advice on how to proceed?
Other ways to reach the goal are also accepted.
I'm not sure if this is doable with ARQuickLook. But we can use either SceneKit or RealityKit ARView and modify the ModelEntity at runtime. You could do something like this, Using ARView in RealityKit:
#IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
let modelURL = URL(string: "https://developer.apple.com/augmented-reality/quick-look/models/drummertoy/toy_drummer.usdz")!
guard let entity = try? ModelEntity.loadModel(contentsOf: modelURL!) else {
print("Entity download failed")
return
}
for child in entity.children {
var newMaterial = SimpleMaterial()
newMaterial.color.tint = UIColor.cyan
child.model?.materials = [newMaterial]
}
let anchor = AnchorEntity(plane: .horizontal)
anchor.addChild(entity)
arView.scene.addAnchor(anchor)
}
Please keep in mind that you will have to manually add the transform/scale actions that you get automatically with ARQuickLook.
We need a realtime database which we can deploy using docker.
I found a Hasura/PostGreSQL docker container which looks like we can use it for our purpose:
https://docs.hasura.io/1.0/graphql/manual/getting-started/docker-simple.html
One thing I figured out was that the URL in the documentation was wrong. It's http://localhost:8080/v1/graphql and not http://localhost:8080/graphql.
But I can't seem to get any results from my subscription...
I get a BAD_ACCESS crash in the package's SplitNetworkTransport.swift
Am I missing something?
My Apollo client code looks like this:
import Apollo
import ApolloWebSocket
class Apollo {
static let shared = Apollo()
let client: ApolloClient = {
let authPayloads = [ "x-hasura-admin-secret": "secret" ]
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = authPayloads
let wsEndpointURL = URL(string: "ws://localhost:8080/v1alpha1/graphql")!
let endpointURL = URL(string: "http://localhost:8080/v1alpha1/graphql")!
let map: GraphQLMap = authPayloads
let websocket = WebSocketTransport(request: URLRequest(url: wsEndpointURL), connectingPayload: map)
let httpNetworkTransport = HTTPNetworkTransport( url: endpointURL, session: URLSession(configuration: configuration))
let splitTransport = SplitNetworkTransport(httpNetworkTransport: httpNetworkTransport, webSocketNetworkTransport: websocket)
return ApolloClient(networkTransport: splitTransport)
}()
}
And I'm calling it as follows:
import UIKit
import Apollo
class ViewController: UIViewController {
private var subscription: Cancellable?
#IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.subscription = Apollo.shared.client.subscribe(subscription: MySubscriptionSubscription()) { [weak self] result in
guard let this = self else { return }
switch result {
case .success(let graphQLResult):
if let data = graphQLResult.data {
this.label.text = "data"
print("Simon Says data: \(data)")//TODO: Remove
}
case .failure(let error):
this.label.text = "error"
print("Simon Says error: \(error)")//TODO: Remove
}
}
}
deinit {
self.subscription?.cancel()
}
}
P.s. I'm using Xcode Version 11.2.1 (11B500), swift 5.1, Apollo swift package 0.20.0 and the docker-compose.yaml from the URL in the Hasura docs linked above.
The workaround is NOT using swift package manager and use COCOAPODS instead.
I want to create test.txt file, sample codes.
I run this app, well done.
But when I debug app step by step, it crash, report
(EXC_BAD_ACCESS(code=EXC_l386_GPFLT)),method:
FileManager.default.createFile()
SWIFT CODES:
import UIKit
class ViewController: UIViewController {
#IBAction func CreateFileButton(_ sender: UIButton) {
createFiles()
}
private func createFiles() {
let manager = FileManager.default
let urlForDocument = manager.urls( for: .documentDirectory,
in:.userDomainMask)
let url = urlForDocument[0]
createFile(name:"test.txt", fileBaseUrl: url)
}
func createFile(name:String, fileBaseUrl:URL){
let manager = FileManager.default
let file = fileBaseUrl.appendingPathComponent(name)
print("f: \(file)")
let exist = manager.fileExists(atPath: file.path)
if !exist {
let data = Data(base64Encoded:"aGVsbG8gd29ybGQ=" ,options:.ignoreUnknownCharacters)
let createSuccess = manager.createFile(atPath: file.path,contents:data,attributes:nil)
print("f: \(createSuccess)")
}
}
}
^ Crash step method:FileManager.default.createFile()
^Crash report
^Just run app, do not debug, it well done
I'm trying to open document file by following way but nothing happens.
I tried other ways too but it didn't work for me. What is the correct way open Document file (doc,docx,pdf,ppt, etc.). I read somewhere by UIWebView() also this can be done so what is the better way?
let fileURL = URL(fileURLWithPath: documentMessage.fileUrl)
let doc = DocumentPreview(fileURL)
doc.startPreview()
DocumentPreview.swift
class DocumentPreview : NSObject, UIDocumentInteractionControllerDelegate {
var url : URL?
var document : UIDocumentInteractionController?
var previewVC : UINavigationController?
init(_ url: URL) {
super.init()
self.url = url
document = UIDocumentInteractionController(url:url)
document?.delegate = self
}
func startPreview(){
document?.presentPreview(animated:true)
}
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return previewVC!
}
func documentInteractionControllerDidEndPreview(_ controller: UIDocumentInteractionController) {
print("end Preview")
previewVC!.popViewController(animated: true)
}
}
Take a look at documentMessage. If the .fileUrl property is a URL, then this code is wrong:
let fileURL = URL(fileURLWithPath: documentMessage.fileUrl)
The simplest fix would be this:
let fileURL = documentMessage.fileUrl
import Foundation
import K
#objc class KU: NSObject {
static func setUpConfigs() {
let productId = TNYEnvironment.sharedInstance().kProductID
let url = TNYEnvironment.sharedInstance().kUrl
K.sharedInstance.configureK(productId,
url: NSURL(string: url)!)
}
static func trackEvent(eventName: String) {
let formattedEventName = eventName.lowercaseString.stringByReplacingOccurrencesOfString(" ", withString: "_")
self.trackEvent(formattedEventName, properties:[:])
}
static func trackEvent(eventName: String, properties: [String: NSObject]) {
let instance = K.sharedInstance
instance.track(eventName, params:properties)
instance.uploadEvents({})
}
}
Its crashing on ipa build, but works fine on debugger. I guess some issue with swift to objc code. Anyone had the same issue?