Flutter: webview_flutter just displays blank (white) on iOS - ios

The bounty expires in 4 days. Answers to this question are eligible for a +50 reputation bounty.
Cedric wants to draw more attention to this question.
I got it to work on Android, the WebViewWidget displays correctly with the html content, no problem.
For iOS it just displays blank/white. I tried what I have seen suggested by people all over the internet, which is to add a few lines to Info.plist, that allow the WKWebView in iOS to load and display http (not secure, not only https):
<key>io.flutter.embedded_views_preview</key>
<string>YES</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
(^^I don't really know what these lines individually do)
(^^I have also tried lowercase "yes" and <true/> as values for the first one)
I ran flutter clean, then flutter pub get, deleted Podfile.lock, ran pod install (in the ios folder) a bunch of times, but I still can't get the content to show in the webview on iOS (it works on Android), only blank white space where the html content is supposed to appear.
It's important to mention that I get my html from neither http nor https, but I load a String (which is html) and set it like this:
String text = ...
await _controller.loadHtmlString(text);
Is there maybe a way of tricking iOS to think that the html comes from https?
These are some common messages I see printed out in the console (not red, just regular color), and I only get these messages when running the app from android studio, not XCode (on a real iOS device):
[assertion] Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
[ProcessSuspension] 0x12d07df20 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'ConnectionTerminationWatchdog' for process with PID=47861, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}
and:
Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
UPDATE: I found out, it also shows a blank/white page on iOS even when I use https, like _controller.loadRequest(Uri.parse('https://flutter.dev'));.

I solved the problem, it was unexpected and not related to http/https stuff... See the comments in below code for explanation
_controller.setNavigationDelegate(
//...
onNavigationRequest: (NavigationRequest request) {
print('onNavigationRequest');
//I first had this line to prevent redirection to anywhere on the internet via hrefs
//but this prevented ANYTHING from being displayed
// return NavigationDecision.prevent;
return NavigationDecision.navigate; //changed it to this, and it works now
},
);
I also removed all those lines from Info.plist, and it still works.

Related

Signing Electron build for M1 macs causes renderer to crash

I've been making intel builds of our Electron app with Electron-Builder for a while, signing them, and being able to run them without issue.
I'm now trying to make an M1/arm build, but it turns out that signing that build causes the renderer to crash. Not signing the build doesn't cause the crash. This isn't an issue for the intel build. (consistent whether build machine is intel or arm, and whether notarize is called subsequently or not)
I see the following during app startup (Note specifically the v8 fatal error at the top, which is the main concern here):
[...]
<--- Last few GCs --->
<--- JS stacktrace --->
[22739:0331/171516.826773:FATAL:v8_initializer.cc(820)]
render-process-gone { reason: 'crashed', exitCode: 5 }
[...]
Error sending from webFrameMain: Error: Render frame was disposed before WebFrameMain could be accessed
at EventEmitter.n.send (node:electron/js2c/browser_init:169:417)
at EventEmitter.b.send (node:electron/js2c/browser_init:165:2494)
at c.<anonymous> (/Users/armelchesnais/Documents/Rave/desktop/dist/mac-arm64/Rave-blue.app/Contents/Resources/app/main.prod.js:2:587569)
at c.emit (node:events:390:28)
at c.emit (node:domain:475:12)
at c.doCheckForUpdates (/Users/armelchesnais/Documents/Rave/desktop/dist/mac-arm64/Rave-blue.app/Contents/Resources/app/main.prod.js:2:993643)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at w.retries (/Users/armelchesnais/Documents/Rave/desktop/dist/mac-arm64/Rave-blue.app/Contents/Resources/app/main.prod.js:2:588005)
Error sending from webFrameMain: Error: Render frame was disposed before WebFrameMain could be accessed
at EventEmitter.n.send (node:electron/js2c/browser_init:169:417)
at EventEmitter.b.send (node:electron/js2c/browser_init:165:2494)
at BrowserWindow.<anonymous> (/Users/armelchesnais/Documents/Rave/desktop/dist/mac-arm64/Rave-blue.app/Contents/Resources/app/main.prod.js:2:632050)
at BrowserWindow.emit (node:events:390:28)
at BrowserWindow.emit (node:domain:475:12)
I won't be able to distribute the arm/M1 build of the app as a result from this.
I'm at a loss as to how signing would affect a crash of the renderer only on one architecture.
How do I resolve this?
electron v17.1.2
electron-builder 23.0.2
I don't know with certainty that we're experiencing the same issue as you, but the following steps fixed an issue like this for our users.
In our case it was caused by native dependencies. The .node files of native dependencies are treated as separate executables which are expected to be signed under normal circumstances. The sandboxing that occurs when they're not seems only to occur on machines with the new M1 chips.
I'm not certain that all of these changes are necessary because we don't have a machine with an M1 chip. I'll update this answer as I whittle it down, but that may take a while given our lack of hardware.
Here's the three changes we've implemented, based on my research:
Ensure your entitlements.plist has at minimum the following. Also ensure you replicate the properties of the default plist for electron-notarize if you use it.
<dict>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
Source
Specify your entitlements file for both entitlements and entitlementsInherit (See docs)
Add the following for asarUnpack
asarUnpack: ['**/*.node']
Please do let me know if this helped!

Getting a LaunchServices error when trying to share to apple Books on ios

I am stuck on a problem, I'm trying to share from my app to Apple Books on iOS. When I perform the share action, the ActivityViewController acts like it is preforming the operation and everything appears to go well, however the shared file never appears in Books.
In the xcode console I get a Launch Services error:
2020-02-09 14:48:25.031316+0700 AppName[1040:282769] [default] LaunchServices: open operation <NSBlockOperation: 0x103006010> failed with error: Error Domain=NSOSStatusErrorDomain Code=-54 "Query not allowed" UserInfo={NSDebugDescription=Query not allowed, _LSLine=320, _LSFunction=-[_LSLocalQueryResolver _enumerateResolvedResultsOfQuery:XPCConnection:withBlock:]}
service was canceled
I've looked around at what could be causing this and from what I can find, it seems most likely that my app does not have the correct permissions to access iBooks, but when I run UIApplication.canOpenURL for the iBooks schemes it comes back as true.
I opened up the simulator console as well where I found a bit more to this error:
Unentitled query <_LSDocumentProxyBindingQuery: 0x10253c750> issued from pid 1021. Disallowing and yielding an error.
Could not find apps for <private>: Error Domain=NSOSStatusErrorDomain Code=-54 "Query not allowed" UserInfo={NSDebugDescription=Query not allowed, _LSLine=320, _LSFunction=<private>}.
Invalid LSOpenOperation request: Error Domain=NSOSStatusErrorDomain Code=-54 "Query not allowed" UserInfo={NSDebugDescription=Query not allowed, _LSLine=320, _LSFunction=-[_LSLocalQueryResolver _enumerateResolvedResultsOfQuery:XPCConnection:withBlock:]}
LaunchServices: [Perform] not launching application - result = Error Domain=NSOSStatusErrorDomain Code=-54 "Query not allowed" UserInfo={NSDebugDescription=Query not allowed, _LSLine=320, _LSFunction=-[_LSLocalQueryResolver _enumerateResolvedResultsOfQuery:XPCConnection:withBlock:]}
But I can't seem to find why the query is unentitled, or how to set it to be allowed.
I have tried adding the ibooks URL scheme to both LSApplicationQueriesSchemes and CFBundleURLTypes but that didn't make a difference.
I also tried saving the file manually and setting the NSFileProtectionKey to none per this post showing the same console error (not completely sure I implemented this correctly however)
I also tried using another app I've created that uses the activityVC to see if that app could share to iBooks and I get the same problem and the same error.
Sharing to all other iOS apps works fine, it is just iBooks that has the problem.
Any point in the right direction would be really appreciated!

Unable to import files with custom UTI extension on IOS 13

Since the update to IOS 13 importing custom UTI files is not working (works perfectly on devices with 12.4)
I've downloaded the simple working project form this page: https://www.raywenderlich.com/813044-uiactivityviewcontroller-tutorial-sharing-data , which i also used as a base for the sharing system of my app.
On IOS 13 (12.4 works), when get the sample file (from email o data folder) and click on Copy To App, IOS goes back to the main screen, and after a few seconds i get a Safari crash error.
This is the project info.plist section for exporting files:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>Book Tracker Document</string>
<key>UTTypeIconFiles</key>
<array>
<string>book_320.png</string>
<string>book_64.png</string>
<string>book_44.png</string>
<string>book_22.png</string>
</array>
<key>UTTypeIdentifier</key>
<string>com.raywenderlich.BookTracker.btkr</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>btkr</string>
<key>public.mime-type</key>
<string>application/booktracker</string>
</dict>
</dict>
</array>
</key>
Things i tried:
Add an UTImportedTypeDeclarations, with the same details as UTExportedTypeDeclarations ones as there is none in the project ---- STILL CRASH
In this post about at the end, was suggested to remove the section from the info.plist (Not modifying the Document Types section) and create it anew from the interface ---- STILL CRASH (it also causes an infinite loop in xcode when adding array items for public.filneame-extension or mime-type)
Various combinations of the solutions above
This is the main error i always get:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
terminating with uncaught exception of type NSException
Full log is here: log
I'm kind of out out ideas! Please help!
I don't have the answer to your question but I have a similar problem with this same sample app from Ray Wenderlich. Unfortunately the comment section for this tutorial is closed.
I am using the "finished" version which has all the UTI information already set.
In my case I want to save the ".btkr" document to the Files application. That works OK but then if I tap on the .btkr document saved in Files, it opens the BookTracker application but quietly fails in the Book.swift importData(from url: URL) method.
I unraveled the guard statement into do/try/catch blocks and what I see is "The file “New Book.btkr” couldn’t be opened because you don’t have permission to view it." This is being thrown from the "let data = try Data(contentsOf: url)" statement.
The odd thing is if I share the same document via eMail, a tap on the .btkr attachment successfully opens the app and imports the .btkr just fine. Share via AirDrop works as well.
I do not know if this is only an iOS 13 bug because I no longer have any devices with older iOS's. Since the tutorials from Wenderlich are generally very good (this one is from February 2019, before iOS 13) I suspect your problem and my problem are iOS 13 bugs.
I'm seeing exactly the same thing here on my app. Wrapping readFromURL and writeToURL in between startAccessingSecurityScopedResource & stopAccessingSecurityScopedResource helped on my iPad running iOS 13.2.3, but I'm still seeing the Safari crash and unable to open the documents on the iPhone running 13.2.2.

What is PBItemCollectionServicer?

I searched SO ,find nothing about PBItemCollectionServicer.
My question become form my app crash(because of memory rise violently), then print:
PBItemCollectionServicer connection disconnected.
The screen shot:
I have no idea about the PBItemCollectionServicer, whats mean of that?
and how does it work?
why it print here?
Is it relate to my app crash?
Edit -1
As Nir's comment, he suspect if I use the under link framework.
https://github.com/JaviSoto/iOS10-Runtime-Headers/tree/master/PrivateFrameworks/Pasteboard.framework
No , I didn't, I searched my project with no result:
Well, I guess those annoying PBItemCollectionServicer logs appear seconds after you copied (Command+ C) something into your iOS devices or iOS simulator which is running apps via Xcode.
The "universal clipboard" service (seems to) collects strings or images to share between your own iCloud devices (Mac, iOS devices ...)
It works in Sierra & iOS 10 environment
Check this article
This log happens only when under simulator/iOS device while running on Xcode, I think.
I don't know why Xcode team let this somewhat should-be-hidden log displayed... for developers? But couldn't find any documentation... blah blah
"PBItemCollectionServicer connection disconnected." also logs when using iOS 11 table view drag-and-drop and completing a drop. It's benign there, from all I've observed.
I was receiving:
Console Log: "PBItemCollectionServicer connection disconnected."
all of a sudden while debugging an iPhone app while connected via the USB cable to my MacBook.
After a bit of searching it turned out that it was hanging for some time because of this line of code where I was clearing the pasteboard:
[pasteBoard setValue:#"" forPasteboardType:UIPasteboardNameGeneral];
After a lot of google searching without any luck I noticed that it only happens when the iPhone was connected to my Mac.
It turned out to be the shared clipboard causing the hang/delay and log message.
If you turn off "Handoff" on the iPhone (Settings/General/Handoff) and Mac (System Preferences/General/Allow Handoff) then the problem was resolved.
The problem also goes away when you disconnect the USB cable from the Mac so it doesn't affect regular use.
For me, the error occurred when PHAssetCollection fetchAssetCollectionsWithType : called with a block predicate:
PHFetchOptions *fetchOptions = PHFetchOptions.new;
// correct
fetchOptions.predicate = [NSPredicate predicateWithFormat:#"localizedTitle = %#", targetAlbumName];
// wrong
// crash with the error message "PBItemCollectionServicer connection disconnected."
//fetchOptions.predicate = [NSPredicate predicateWithBlock:xxx];
PHAssetCollection * assetCollection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:fetchOptions].firstObject;
I found that when working with drag and drop this error gets cleared up when adding
view.addInteraction(UIDropInteraction(delegate: self))
to the viewDidLoad of the view you are dropping into.
Firstly, this is not an answer to the question. And I failed to find one. It's just some information I think may be helpful for someone who can dig into this and find an answer.
I was tinkering with the copy(_:), cut(_:) and paste(_:) functions of UITextField. Almost every time I did copy/cut/paste in in field, the Xcode gave this message:
2020-07-17 15:45:38.796510+0800 MyApp[3062:1763915] [general] Connection to daemon was invalidated
2020-07-17 15:45:54.179188+0800 MyApp[3062:1763859] PBItemCollectionServicer connection disconnected.
2020-07-17 15:46:53.097783+0800 MyApp[3062:1763859] PBItemCollectionServicer connection disconnected.
2020-07-17 15:46:57.180499+0800 MyApp[3062:1763859] PBItemCollectionServicer connection disconnected.
2020-07-17 15:48:34.901502+0800 MyApp[3062:1764656] PBItemCollectionServicer connection disconnected.
The only relevant code is an extension to UITextField:
extension UITextField {
open override func copy(_ sender: Any?) {
print(sender)
print(text)
}
open override func paste(_ sender: Any?) {
print(sender)
print(text)
}
open override func cut(_ sender: Any?) {
print(sender)
print(text)
}
}
And none of them was called. How weird. Then I commented out this extension, and to my surprise, Xcode still gave the exactly same message. Anyway, after I searched here and there, I found this in Apple Developer Forums, which is discussion about the failure of UIDropInteraction with the same error message. As all the other answers mostly talked about UIPasteboard, I think it is necessary to put it here although it doesn't contain a solution or answer.
I tried running on both Simulator(13.5) and device(13.4.1), with Xcode 11.5, and got the same error message.
I was also receiving a PBItemCollectionServicer connection disconnected line in the console log, when testing an UICollectionViewDragDelegate implementation.
It turned out that my Info.plist file didn't have that required NSUserActivityTypes configuration with the activity identifier of the NSUserActivity used in the NSItemProvider as part of the dragged UIDragItem. After fixing this, the drag-and-drop action finally worked, and the console did log the mysterious line anymore.
In order to make sure drag-and-drop works for you,
you need to specify your type identifier (e.g. com.xxx.TodoList.todoItem) in Info.plist like this:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.text</string>
</array>
<key>UTTypeDescription</key>
<string>com.xxx.TodoList.todoItem</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>com.xxx.TodoList.todoItem</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array/>
</dict>
</dict>
</array>

NSURLSession/NSURLConnection HTTP load failed and other AdMob warnings for iOS 9

I have an existing app in the App Store that supports both iOS 7 and 8 (though I'll be dropping iOS 7 support shortly).
My latest version of the app has brought both IADs and AdMobs (where AdMobs act as a failover from IADS). With the upcoming launch of iOS 9, and the recent craze of Google requiring the removal of SSL (http://googleadsdeveloper.blogspot.ch/2015/08/handling-app-transport-security-in-ios-9.html
HTTPS request in iOS 9 : NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)), from a beginner's point of view, I'd like to ask about some warnings I'm getting with my app running in Xcode 7 beta 5.
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
There's this link that I came across as well http://timekl.com/blog/2015/08/21/shipping-an-app-with-app-transport-security/?utm_campaign=iOS%2BDev%2BWeekly&utm_medium=email&utm_source=iOS_Dev_Weekly_Issue_213
So, what exactly do I need to do to remove this warning from the console when running my app on iOS 9?
I've come across one list that talks about disabling botched in Xcode, but firstly I don't understand what disabling that does, but also, is that required for this? What does ENABLE_BITCODE do in xcode 7?
Any thoughts on this would be really appreciated.
Read this App Transport Security Technote
Chances are, you'll have to set the NSAllowsArbitraryLoads to YES globally for now, because you aren't in control over what servers your ads come from.
Add below syntax to your app's info.plist,It's work for me.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
because your are calling a server which has self-signed certificate. you have to by pass it.

Resources