PhantomAppDevelopment / firebase-as3

Integrate Firebase Auth, Realtime Database and Storage in your Adobe AIR projects.
MIT License
55 stars 12 forks source link

not Working on Device(AIR) #2

Closed Seb-AS closed 8 years ago

Seb-AS commented 8 years ago

HI, The code works fine in the Air simulator, but don't work on device, I think is related to the URLStream.

I'm using myflashlabs anes for device, and your examples for debugging.

Thanks for the examples

~Sebas

agentphantom commented 8 years ago

Hi,

In which devices doesn't work and what error message did you get?

Seb-AS commented 8 years ago

IOS(iphone 6s, ipad air 2) don't work, Android works fine

Exact same code.

ReferenceError: Error #1069: Property data not found on flash.net.URLStream and there is no default value

agentphantom commented 8 years ago

URLStream does not have a data property, you use the bytesAvailable property (inside a ProgressEvent.PROGRESS event). Like this:

var message:String = messagesStream.readUTFBytes(messagesStream.bytesAvailable);

URLStream is only used for reading a database in real time, for regular requests you use URLLoader with its data property (using the flash.events.Event.COMPLETE listener).

Seb-AS commented 8 years ago

yes, the code it's as you said.

The code is basically a copy/paste using a different Firebase_id

For some reason the code works fine on Android but not on IOS 10.0.2(latest AIR 23).

agentphantom commented 8 years ago

I was researching about issues with URLStream and iOS but couldn't find anything relevant.

Maybe it's an issue with iOS 10, we can only wait for it to get fixed in upcoming AIR releases.

reyco1 commented 8 years ago

Im actually having a very similar problem saving data to the Firebase database. It works great when I test in the development environment on my computer. I am able to save to the database, but when I try and do the same thing on my test iOS device, it does not save and I get back a Error #2032: Stream Error with an empty data variable and I have no way of knowing what the issue is. I really do not want to use an ANE so I'm hoping we can find a solution :(

agentphantom commented 8 years ago

This is very odd, does it happen with and without an Auth token?

Also, does it happen on regular requests or only real time ones?

One theory is that the NSAppTransportSecurity isn't working with the Firebase servers, but they are SSL by default so it might not be it. <-- Turns out I was right.

Unfortunately I don't have a modern iOS device so I'm unable to test in iOS. On Android and OSX it works great.

It leaves us with something iOS specific. If you wish I can create a very simple project, help me testing in iOS and if it doesn't work I will submit a bug report to Adobe.

reyco1 commented 8 years ago

Yeah man, if you can create an uber simple project and send it over so that we could test that would be great... Im stumped.

agentphantom commented 8 years ago

I have attached a very simple Flex mobile app, it doesn't require any permissions, just copy and paste into a Blank Application (if using Flash Builder).

I left the url of my test project, you are free to change it. The Firebase rules are simple:

"rules": {
"messages": { ".read": true, ".write": true } }

I successfully tested it on Sierra and Lollipop. Good luck!

Main.zip

reyco1 commented 8 years ago

Does not load the messages and does not send the messages from my ios device... Im so confused.

agentphantom commented 8 years ago

Your two messages got recorded in the database.

"test message from rey from mac book pro (should work) 384.34082735329866" "now testing from iPhone 5 with latest update 617.1470680274069"

But you are not receiving the responses from Firebase.

I have some questions before I create the bug report:

Is the Event.COMPLETE fired after you load and send messages? (you can add a simple trace("Loaded") to test).

Can you load the messages from your Mac (using AIR simulator or desktop AIR app)? Can you access the URL using a web browser?

reyco1 commented 8 years ago

Both of those messages were sent from the dev environment. None came from my ios device... I just forgot to update the message when I ran it from my local environment again. I can see the message in my web browser and I can run the emulator on my Mac and send and receive from there, no issues. Problem comes when I run the app on my ios device. I load and I send but nothing happens

agentphantom commented 8 years ago

Ah got it!

I will create a bug report and post the link here and on social media.

reyco1 commented 8 years ago

Man, I guess I will have to use an ANE then... I was really not looking forward to that :(

agentphantom commented 8 years ago

Let's hope it gets fixed soon. You can try a workaround using a basic proxy with PHP.

Here's the bug report link: https://bugbase.adobe.com/index.cfm?event=bug&id=4196454

reyco1 commented 8 years ago

I just voted on it

reyco1 commented 8 years ago

@agentphantom what ios device and what os version are you using to test, if I may ask?

agentphantom commented 8 years ago

I suspended iOS development a few years ago, my last device was an iPod Touch 4th gen (which is now obsolete from AIR 20+).

Right now I only work on Android and Mac/Win. I was gonna return to iOS dev with some Firebase projects but it seems I will have to wait.

reyco1 commented 8 years ago

Its crazy because something as simple as loading this does not work :-/ "https://burning-heat-6389.firebaseio.com/messages.json"

reyco1 commented 8 years ago

By the way, the problem only happens with Firebase... I replaced your URL with "https://randomuser.me/api/" which is a secure api that generates random user data for testing and it worked on my device.

agentphantom commented 8 years ago

Yeah, it got me intrigued. Right now we can only narrow down what exactly is failing.

Do other URLs (with and without SSL) work? Here's a public API url:

https://maps.googleapis.com/maps/api/directions/json?origin=Doncaster&destination=Manchester,England

Have you tried to do it with StageWebView? You can try loading my site: https://phantom.im, it is hosted on Firebase servers.

reyco1 commented 8 years ago

We posted at the same time :) Check my last post

reyco1 commented 8 years ago

Your link worked as well

agentphantom commented 8 years ago

I did a quick research, it seems it's actually a bigger issue on native iOS: https://firebase.googleblog.com/2016/08/ios-10-xcode-8-and-swift-3.html

Also, worth checking: https://groups.google.com/forum/#!forum/firebase-talk

I will keep reading and see if I find something useful.

agentphantom commented 8 years ago

I found something interesting: http://stackoverflow.com/questions/38934823/firebase-sdk-doesnt-work-with-ios-10

reyco1 commented 8 years ago

Hmmmm... That's insane! I wonder if there is any way around that

Seb-AS commented 8 years ago

Hey guys, I'm not in home to test, but I was reading the comments.

I think is not a bug with firebase and ios 10, because I can use it with myflashlabs anes, take a while to configure but works.

agentphantom commented 8 years ago

Thank you!

So far we have:

*Updated: HTTPS (Google Directions API) works in iOS in AIR. Firebase Storage and Auth work in iOS in AIR. The ANE works. Native Firebase had troubles at first, and they needed to rework them. https://firebase.googleblog.com/2016/09/announcing-firebase-36-for-ios.html

But Firebase REST doesn't work on iOS 10. But what's different from the Firebase API to Google Directions API, both are REST, HTTPS and return a JSON file.

Maybe some hidden flag in the .plist?

reyco1 commented 8 years ago

@Seb-AS It has to be an issue with ios 10 and firebase, man. Other secure rest apis work just fine.

reyco1 commented 8 years ago

@agentphantom one difference I see is the ".json" which is mandatory for the Firebase API

agentphantom commented 8 years ago

Good point, I got an idea. The following URLs are from a test picture:

Actual picture https://firebasestorage.googleapis.com/v0/b/pizza-app-2a586.appspot.com/o/images%2F1476294589726.jpg?alt=media

Metadata (it returns a JSON) https://firebasestorage.googleapis.com/v0/b/pizza-app-2a586.appspot.com/o/images%2F1476294589726.jpg

Tou can try loading those urls in iOS and check if they work.

reyco1 commented 8 years ago

@agentphantom both worked on iOS

agentphantom commented 8 years ago

Good, Storage is working fine, it narrows down to the database (I don't know if Auth works).

reyco1 commented 8 years ago

Auth works. I have tested with email and Facebook. I just cant read or write to a Firebase DB fro iOS :(

agentphantom commented 8 years ago

Excellent, there's another way to test the Database.

The SecureSocket class: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SecureSocket.html

It is a bit hard to set up, it requires plenty of event listeners (the Adobe docs are super simple, it acutally requires like 6 event listeners).

reyco1 commented 8 years ago

Let me run a test...

reyco1 commented 8 years ago

@agentphantom have any SecureSocket sample code I can implement? I never used that class before to load a json file.

reyco1 commented 8 years ago

btw @Seb-AS , MyFlashLab wants $150 for all of their Firbase ANEs :( You can't just buy one since they all depend on eachother

agentphantom commented 8 years ago

This is the general idea of how to use a socket: https://github.com/denisdanielyan/as3-Application-Only-Twitter/blob/master/Twitter-Application-Only/src/de/danielyan/twitterAppOnly/TwitterSocket.as#L108

http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b0-181c51321220efd9d1c-8000.html

The port for SSL is 443.

You don't require AS3crypto since Adobe has already implemented SSL on their socket class. Since you only need to do a basic GET request you won't require most of those extra parameters from the first example.

reyco1 commented 8 years ago

UPDATE: I tried adding the contents of the plist file provided by Firebase to my app xml and that didnt work either

reyco1 commented 8 years ago

I would use the MyFlashLabs ANE but I just dont want to dish out $150!

agentphantom commented 8 years ago

I forgot to add some event listeners to the Flex file. They may have some useful info:

httpResponseStatus httpStatus securityError

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html

reyco1 commented 8 years ago
[trace] openHandler: [Event type="open" bubbles=false cancelable=false eventPhase=2]
[trace] httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=0 redirected=false responseURL=null]
[trace] ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: https://burning-heat-6389.firebaseio.com/messages.json" errorID=2032]
agentphantom commented 8 years ago

I think I found it: http://stackoverflow.com/questions/31345273/ios-9-ats-and-firebase-rest

reyco1 commented 8 years ago

Holy shit that worked!!! Great investigation work, man!

I had:

<key>firebaseio.com</key>
<dict>
    <key>NSExceptionAllowsInsecureHTTPLoads</key>
    <true/>
    <key>NSIncludesSubdomains</key>
    <true/>
    <key>NSExceptionRequiresForwardSecrecy</key>
    <true/>
</dict>

and I changed it to

<key>firebaseio.com</key>
<dict>
    <key>NSIncludesSubdomains</key>
    <true/>
    <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
    <false/>
</dict>

And that did it!!! I'm able to both read and write to the DB

reyco1 commented 8 years ago

Make sure you add it to the READ.me :)

agentphantom commented 8 years ago

Of course! I will cancel the bug report.

reyco1 commented 8 years ago

Thanks for all your hard work man! By the way, Are all your Firebase projects (ToDo and others) up to date? Thanks!

agentphantom commented 8 years ago

This repo's examples are up to date. ToDo will get some refactoring this week.

Tomorrow I will release a big cool app that uses DB, Auth and Storage. Stay tuned!

reyco1 commented 8 years ago

Cant wait! Thanks @agentphantom !!