Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Immediate Crash #23

Closed
roblav96 opened this issue Sep 6, 2016 · 5 comments
Closed

[iOS] Immediate Crash #23

roblav96 opened this issue Sep 6, 2016 · 5 comments

Comments

@roblav96
Copy link

roblav96 commented Sep 6, 2016

My app crashes and I get this error when trying to upload a file on iOS 馃槩

Source

<ListView row="0" [items]="_images" (itemTap)="onItemTap($event)">
    <template let-item="item">
        <Image [imageSource]="item"></Image>
    </template>
</ListView>
import {Folder, FileSystemEntity, knownFolders, File, path} from "file-system"
import {ImageSource, fromFile, fromUrl} from "image-source"
import {ImageFormat} from "ui/enums"
import {Session, Task, session} from "nativescript-background-http"

onItemTap(args: ItemEventData) {

    let image: ImageSource = this._images[args.index]
    let folder: Folder = knownFolders.documents()

    let fileName: string = "IMAGE_FILE.png"
    global.tnsconsole.log('fileName', fileName) // IMAGE_FILE.png

    let filePath: string = path.join(folder.path, fileName)
    global.tnsconsole.log('filePath', filePath) // /var/mobile/Containers/Data/Application/EB845FC8-96DE-4FAB-95F8-93B78DB38724/Documents/IMAGE_FILE.png

    if (image.saveToFile(filePath, ImageFormat.png)) {

        let sesh: Session = session("image-upload")
        let options: any = {
            url: 'http://192.168.0.2:8083',
            method: 'POST',
            headers: {
                'Content-Type': 'application/octet-stream',
                'File-Name': fileName
            },
            description: '{ \'uploading\': ' + fileName + ' }'
        }
        let task: Task = sesh.uploadFile(filePath, options)

        task.on('progress', logEvent)
        task.on('error', logEvent)
        task.on('complete', logEvent)

    }

    function logEvent(e) {
        console.log(e.eventName)
    }
}

Error

CONSOLE LOG file:///app/dev/tns.console.js:107:22: 
[LOG] 06:09:32:993 itemTap_9_0
fileName > IMAGE_FILE.png

CONSOLE LOG file:///app/dev/tns.console.js:107:22: 
[LOG] 06:09:32:995 itemTap_9_0
filePath > /var/mobile/Containers/Data/Application/EB845FC8-96DE-4FAB-95F8-93B78DB38724/Documents/IMAGE_FILE.png

1   0x5a56d3 NativeScript::FFICallback<NativeScript::ObjCMethodCallback>::ffiClosureCallback(ffi_cif*, void*, void**, void*)
2   0x987c15 ffi_closure_inner_SYSV
3   0x98b0b8 ffi_closure_SYSV
4   0x25e5dc23 <redacted>
5   0x25f1749d <redacted>
6   0x25f237af <redacted>
7   0x25c5f799 <redacted>
8   0x2164f2b1 <redacted>
9   0x2164d5a7 <redacted>
10  0x2164d9e5 <redacted>
11  0x2159c1c9 CFRunLoopRunSpecific
12  0x2159bfbd CFRunLoopRunInMode
13  0x22bb8af9 GSEventRunModal
14  0x25cd5435 UIApplicationMain
15  0x98b02c ffi_call_SYSV
16  0x987959 ffi_call
17  0x5774b7 NativeScript::FFICall::call(JSC::ExecState*)
18  0x7c50ab JSC::LLInt::setUpCall(JSC::ExecState*, JSC::Instruction*, JSC::CodeSpecializationKind, JSC::JSValue, JSC::LLIntCallLinkInfo*)
19  0x7c2e61 llint_slow_path_call
20  0x7cac7d llint_entry
roblav96@Roberts-iMac:/Volumes/OSX HD/Projects/sandbox/client$

package.json

"nativescript": {
    "id": "com.roblav96.sandbox",
    "tns-android": {
        "version": "2.2.0"
    },
    "tns-ios": {
        "version": "2.2.1"
    }
},
"dependencies": {
    "@angular/common": "2.0.0-rc.5",
    "@angular/compiler": "2.0.0-rc.5",
    "@angular/core": "2.0.0-rc.5",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.5",
    "@angular/platform-browser": "2.0.0-rc.5",
    "@angular/platform-browser-dynamic": "2.0.0-rc.5",
    "@angular/platform-server": "2.0.0-rc.5",
    "@angular/router": "3.0.0-rc.1",
    "@ngrx/core": "1.0.2",
    "@ngrx/store": "^2.1.2",
    "ansicolors": "latest",
    "ansistyles": "latest",
    "lodash": "latest",
    "lokijs": "latest",
    "moment": "latest",
    "nativescript-angular": "0.4.0",
    "nativescript-background-http": "latest",
    "reflect-metadata": "0.1.3",
    "rxjs": "5.0.0-beta.6",
    "tns-core-modules": "2.2.1",
    "zone.js": "0.6.12"
},

Using the latest version with the example server.js backend supplied in this repository.

@karan1149
Copy link

Also having this issue.

@NickIliev
Copy link
Contributor

Hey @roblav96 , @karan1149 did you guys still reproduce this with the latest version of the plugin and the tis-core-modules?

@roblav96
Copy link
Author

roblav96 commented Oct 24, 2016

@NickIliev I have not tried using this since the original post up top.

I ended up wiping together something small using AFNetworking:

private static _downloadData(): Promise<NSURL> {
    return new Promise(function(resolve, reject) {
        let file: string = 'Archive'
        let config: NSURLSessionConfiguration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier('com.roblav96.sandbox')
        let manager: AFURLSessionManager = AFURLSessionManager.new().initWithSessionConfiguration(config)
        let url: NSURL = NSURL.URLWithString(IP + '/tessdata/' + file + '.zip')
        let request: NSURLRequest = NSURLRequest.requestWithURL(url)
        let downloadTask: NSURLSessionDownloadTask = manager.downloadTaskWithRequestProgressDestinationCompletionHandler(
            request,
            function downloadProgressBlock(progress: NSProgress) {
                let value: number = Math.min(progress.completedUnitCount / progress.totalUnitCount, 99)
                TesseractClass.emitter.emit('progress', value)
            },
            function destination(targetPath: NSURL, response: NSURLResponse): NSURL {
                let tessdata: Folder = knownFolders.temp().getFolder('tessdata')
                let nsurl: NSURL = NSURL.fileURLWithPath(tessdata.path + '/' + file + '.zip')
                return nsurl
            },
            function completionHandler(response: NSURLResponse, filePath: NSURL, nserror: NSError) {
                if (nserror) {
                    let error: any = (nserror.description) ? nserror.description : nserror
                    global.tnsconsole.error('downloadData > error', error)
                    reject(error)
                } else {
                    resolve(filePath)
                }
            }
        )
        downloadTask.resume()
    })
}

I'll check this and see if it's working. I'm always deving on @next everything.

@roblav96
Copy link
Author

@NickIliev I can confirm that the latest version works flawless on android and ios :D

@shivgolani
Copy link

@roblav96 can you help me if I want to download multiple files. Your code is allowing only single file download.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants