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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash when using a NativeScript app (for alternate icon name) #116

Closed
wants to merge 4 commits into from

Conversation

EddyVerbruggen
Copy link

After showing a Toast my app would crash when using this method.

I have very little experience in Swift so I don't know why the rootViewController getter needs to be hijacked by this pod, but to make it work for my case I'd really love to have this code merged.

After showing a Toast my app would crash when using [this method](https://developer.apple.com/documentation/uikit/uiapplication/2806818-setalternateiconname).

I have very little experience in Swift so I don't know why the `rootViewController` getter needs to be hijacked by this pod, but to make it work for my case I'd really love to have this code merged.
@devxoul
Copy link
Owner

devxoul commented Aug 28, 2017

Can you share the way to reproduce the crash?

@EddyVerbruggen
Copy link
Author

Good question. I just tried reproducing it with your demo and sadly for me I can't.

If I add a breakpoint to the rootViewController getter I notice that your demo will hit that method when a Toast is shown, but not when it's used inside a NativeScript app (that's my usecase).

Funny thing is that when the method to change the icon runs, both a native Swift app and a NativeScript app hit the aforementioned getter. But in the NativeScript case we need the fallback this PR was created for.

I hope that fallback doesn't bother you as it's quite similar to what you have until recently. If you're not going to merge it I'm afraid I have to use my own fork.

Btw, the screenshot below is proof that your code is compatible with the icon change feature of iOS 10.3 (unless it runs in a NativeScript app (and perhaps Cordova and React Native as well)):

Thanks for considering anyway and keep up the great work!

simulator screen shot 28 aug 2017 23 53 09

@devxoul
Copy link
Owner

devxoul commented Aug 29, 2017

@EddyVerbruggen I would definitely love to patch a bug if it exists. But changing rootViewController can be a critical change (because Toaster has no test 😂) so I wanted to know the exact situation. Can you reproduce the bug with a new project? (not a demo)

@EddyVerbruggen
Copy link
Author

@devxoul I can reproduce it with a NativeScript app, not with a Swift app. Would that be of help?

@devxoul
Copy link
Owner

devxoul commented Aug 30, 2017

Hmm. Does NativeScript app have different window hierarchy from native Swift app?

@Coeur Coeur changed the title Prevent crash when using alternate icon name Prevent crash when using a NativeScript app (for alternate icon name) Apr 3, 2019
@Coeur
Copy link
Collaborator

Coeur commented Apr 3, 2019

@EddyVerbruggen you seem to work at NativeScript.
I'll try to reproduce your issue in order to review the pull request.

I've done those install steps:

brew install node@10
echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
pip install six
npm install -g nativescript

I've done those cocoapods setup steps:

tns create MYCocoaPodsApp
cd MYCocoaPodsApp
tns platform add ios
cd ..
mkdir my-plugin
cd my-plugin
touch package.json
echo '{"name":"my-plugin","version":"0.0.1","nativescript":{"platforms":{"ios":"1.3.0"}}}' > package.json
mkdir platforms
mkdir platforms/ios
touch platforms/ios/Podfile
echo "pod 'Toaster'" > platforms/ios/Podfile
cd ../MYCocoaPodsApp/
tns plugin add ../my-plugin
tns build ios
open platforms/ios/MYCocoaPodsApp.xcworkspace

Now I need to figure out how to call Toaster from javascript. I'll be back once I figure it out.

@EddyVerbruggen
Copy link
Author

@Coeur Much appreciated! For your last comment, perhaps this can be of help: https://github.com/EddyVerbruggen/nativescript-toast/blob/master/toast.ios.js

@Coeur
Copy link
Collaborator

Coeur commented Apr 3, 2019

[edit] OK, next:
We add (new Toast("Hello Toaster", 0, 2.0)).show(); in main-view-model.js, and for every change in a pod we must run:

tns plugin add ../my-plugin
tns run ios --bundle

(nice thing is that changes in .js are applied on the fly)

But with current devxoul/Toaster:master branch, we get:

JS ERROR Error: No initializer found that matches constructor invocation.

@EddyVerbruggen
Copy link
Author

@Coeur If that's undefined, it means the Pod isn't actually loaded. Your steps seem OK though so I'm curious. Can you share your project? Otherwise I'll have to retrace your steps and I may end up doing it slightly differently.

@Coeur
Copy link
Collaborator

Coeur commented Apr 3, 2019

I've fixed the issue by using your fork, like that: https://github.com/Coeur/nativescript-toaster/commit/1e6d422d3902a4c1ed4e590ce625b78fe98484c5
I guess that those missing @objc were the issue...

[edit]
I'll continue looking at the PR tomorrow: got to go for now.

@EddyVerbruggen
Copy link
Author

@Coeur The missing @objc's are one thing that I had to change, but to fix the issue this PR tries to address this change was needed as well.

So to reiterate, showing a Toast works, but if you would use this method the app would crash. If you did not show a Toast beforehand, the app would not crash.

@Coeur
Copy link
Collaborator

Coeur commented Apr 4, 2019

Let's address the Objective-C compatibility in a pull request of its own: #147.
Once done, we can come back here to that issue with setAlternateIconName in NativeScript.

@Coeur
Copy link
Collaborator

Coeur commented Apr 8, 2019

@EddyVerbruggen I've added a call to setAlternateIconName without triggering any crash: https://github.com/Coeur/nativescript-toaster/commit/0c4ab8196e98fe71f494a817eb6a7e04f19d3084
But I wasn't successful at actually setting the AppIcon-2 resource in a NativeScript project, so to be honest, setting the alternateIconName isn't currently working in my hands.

Could you provide a sample MCVE of the crash issue? Maybe a simple fork of https://github.com/Coeur/nativescript-toaster/ ?

@Coeur
Copy link
Collaborator

Coeur commented May 14, 2019

@EddyVerbruggen As I can't reproduce the issue that you're facing, I'll close this PR for now.
If you get an MCVE (see my previous comment), then we can reopen it. Thank you.

@Coeur Coeur closed this May 14, 2019
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

Successfully merging this pull request may close these issues.

3 participants