Now that live previews are available in UIKit (source: https://developer.apple.com/wwdc23/10252)
I was wondering how to get a UIViewController from Objective-C. The Swift macro looks like this:
#Preview {
var controller = SomeViewController()
return controller;
}
Is there a way to get a live preview for UIViewControllers/UIViews written in Objective-C (other than wrapping it as a child view controller in an empty swift view controller)?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
In NSFileManager there is this method to move files to and from iCloud:- (BOOL)setUbiquitous:(BOOL)flag itemAtURL:(NSURL *)url destinationURL:(NSURL *)destinationURL error:(NSError **)errorOutAll the samples and information I'm able to find seem to be related to using NSDocument, which my app isn't using. I have a little view in my app that allows users to move an image out from the iCloud container and into a local directory. It seems that simply using NSFileManager moveItemAtURL:toURL:error: works fine both to move a file in and out of the iCloud container on OS X without wrapping everything in a file coordinator block. Is it still necessary to use a file coordinator to move files out of iCloud on the Mac. When I put a file in the iCloud container, the system automatically starts uploading it..even though I'm not using a file coordinator...and my related file presenter still is detecting a change.Both methods seem to be working the same, I'm just wondering if I should be using a coordinator because it's a good amount of code I can get rid of if it's not necessary.Thanks.
I have a horizontal section in my compositional layout with three items.
0 ---- 1 ----2
When scrolling toward the center I want the scrolling to snap the item at index 1 to the center of the screen. However I can't figure out how to precisely control horizontal scrolling with compositional layout (it doesn't seem possible to control the contentOffset of horizontal scrolling). When I enable paging using UICollectionLayoutSectionOrthogonalScrollingBehaviorPaging the page size assumes full device width and paging works for the item at index 0 or 2 but then the item at index 1 can never be displayed fully on screen (only one half of its width can be shown at a given time).
I tried adding leading and trailing space to the group but that didn't work. When I try the UICollectionLayoutSectionOrthogonalScrollingBehaviorGroupPaging the section is displayed with the item at index 1 centered but scrolling doesn't work.
I think what I'm looking for is UICollectionLayoutSectionOrthogonalScrollingBehaviorGroupPaging but at the item level or to be able to adjust the contentOffset on the scroll view at the end of dragging.
Is there any way I can programmatically access the scroll view being using for horizontal scrolling? I see in the visibleItemsInvalidationHandler I'm able to get the content offset but I'm not able to change it to support snapping.
I'm using compositional layout with UICollectionView. In a particular section I configure the compositional layout to use an estimated height because I want self sizing items determined by Autolayout Constraints.
Now I have a custom content configuration with autolayout constraints. At runtime I hit this log about conflicting constraints:
[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
[...]
<NSLayoutConstraint:0x6000024af160 UIImageView:0x120745520.height == 130 (active)>
<NSLayoutConstraint:0x6000024af2a0 MyCustomContentView :0x120748d60.height >= 1.04839*UIImageView:0x120745520.height (active)>
<NSLayoutConstraint:0x6000024b08c0 'UIView-Encapsulated-Layout-Height' UICollectionViewListCell:0x1214392f0.height == 44 (active)>
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000024af160 UIImageView:0x120745520.height == 130 (active)>
The "UIView-Encapsulated-Layout-Height" on UICollectionViewListCell with a value of 44.0 appears to be a constraint created by the system. I'm not sure why a hard coded height of 44.0 is being used when the compositional layout is returning a section that only uses estimated heights (created via NSCollectionLayoutDimension estimatedDimension).
Any ideas how I can avoid this? I'm not using custom UICollectionView cells but I am using a custom content configuration and a custom content view and setting my content configuration on a UICollectionViewListCell.
I'm Using UICollectionViewCompositionalLayout with a section provider and I set the NSCollectionLayoutSectionVisibleItemsInvalidationHandler on a particular section.
The NSCollectionLayoutSectionVisibleItemsInvalidationHandler hands back an array of objects conforming to the NSCollectionLayoutVisibleItem protocol which has a name property which always appears to be nil.
I figured there must be a way to use this name property to make it easier to do look up for the NSCollectionLayoutVisibleItem objects I'm actually looking. Is there a way to make this property nonnil?
Does it get set to the UICollectionViewCell's reuse identifier or something (I'm currently using UICollectionViewCellRegistration)?
Is there any documentation on the name property? https://developer.apple.com/documentation/uikit/nscollectionlayoutvisibleitem/3199122-name?language=objc
In a SwiftUI source file Xcode displays a window with a Split View. The first split is the source code and the second split is the preview.
My question is, is there a way for me to have the preview take over the entire window width (I want to collapse the source code pane and just look at the preview)?
I can easily collapse the Preview pane by dragging the split to the right to collapse (but it doesn't work in reverse). I also can toggle the preview pane by going to Editor -> Canvas in the Menu bar.
Currently I'm using SwiftUI just to get a live preview of UIKit view controllers so I'm not interested in looking at the SwiftUI source code, though I imagine displaying a full window preview in a separate window would be useful for SwiftUI developers too. You could edit the source code on one monitor and have the preview window on an external display. Is this not possible?
I have an iOS app that was rejected and I submitted a revised binary. In my case auto-renewable subscriptions were returned with the initial rejections and I didn't realize I had to add them for review again with my revised submission....so I submitted a revised binary which got rejected because the subscriptions were returned on the initial rejection.
So I go to "Subscriptions" area for my app and the status is "Developer Action Needed." If I click a subscription the "Submit for Review" button is disabled. I tried making an edit to the Subscription to see if that would cause the button to become enabled but it does not. Can't figure out how I can resubmit these subscriptions for review....so my submission is stuck...
Perhaps when an app with attached iAP/Subscriptions is rejected they shouldn't detach iAP/subscriptions from the app? Developers can easily not notice and submit a new build and not realize that their iAP/subscriptions are no longer attached to the build...and if App Review doesn't notice you could have an app get on the Store which potentially shows UI for non-working iAP/subscriptions.
If anyone has ran into this and could help I'd appreciate it. Thanks a lot.
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
App Store Connect
StoreKit
I see WKContentRuleListStore saves compile lists by identifier. It's nice that I don't have to recompile the WKContentRuleListStore on every app launch but is there ever an event where the system discards compiled lists (other than me calling -removeContentRuleListForIdentifier:completionHandler:)?
The reason I ask is should I be writing a version number with my compiled list? If I change the JSON code on an app update do I need to manually remove compiled lists after an app update before recompiling the new JSON?
I see in the documentation that it is possible to hide elements on a page using a CSS selector by setting the action type to css-display-none and then providing a selector.
But this is kind of limited. You have to know every selector for every style sheet ahead of time. It's possible to block loading of a style sheet using a block rule.
"trigger" : {
"load-type" : [
"third-party"
],
"url-filter" : "REGEX_FOR_STYLESHEET_OF_KNOWN_NASTY_CONTENT_PROVIDER",
"resource-type" : [
"style-sheet"
],
"url-filter-is-case-sensitive" : true
},
"action" : {
"type" : "block"
}
Is is my understanding that the above rule will block loading of a stylesheet that matches the url-filter but all elements will still be displayed by WKWebView using the default style provided by the browser. Am I misunderstanding?
Ideally I'd like to be able to set display:none; for every selector in the evil style sheet. I of course can look at the style sheet and make css-display-none rules for every selector manually but that's pretty much impossible to maintain for rule lists with thousands of entires and will break when the author of the nasty stylesheet makes any changes.
Is there a way to accomplish what I'm after using WKContentRuleList?
When trying to compile a rule list via WKContentRuleListStore's -compileContentRuleListForIdentifier:encodedContentRuleList:completionHandler: method I'm getting the following error:
** Rule list compilation failed Too many rules in JSON array.**
The max number of rules allowed in a WKContentRuleList doesn't seem to be documented (or I couldn't find it). Does anyone know what the limit is?
Thanks
I need to prepare an object when the user navigates to a new page in WKWebView and refresh UI. I run a WKUserScript on behalf of the user to do this.
I'm using the readystatechange event listener to detect initial page load. I'm also listening to the visibilitychange event to refresh UI if the DOM is already loaded on a "Go back" or "Go Forward" action.
document.addEventListener('visibilitychange', () => {
//do whatever if the DOM is already loaded and if we are visible.
});
document.addEventListener('readystatechange', (event) =>
{
//do whatever when page is loaded
});
On certain websites however I noticed that neither of these events are being fired when I navigate -goForward: and -goBack:
I'm not sure why. My WKUserScript is in WKContentWorld.defaultClientWorld so it shouldn't be interfering with the javascript of the page. Is there another JS event I'm missing?
I could pick up the changed URL on the native code side but it would be nice to keep this all contained within the WKUserScript as this UI is for the "webview" and the native code shouldn't have to be bothered with having to patch in the additional glue. Is there another DOM event I need to listen to? I tried listening to window's pageshow but that didn't work. Also experimented a bit with the window's popstate event but no luck.
It appears a lot of useful WWDC session videos from previous years have been scrubbed from the developer.apple.com? I cannot find the WWDC session "Customized Loading in WKWebView" from 2017 in the Developer app nor on the developer website.
There are lots of other videos that would be useful to watch, even from years ago. Am I just not looking in the right place?
Is there a way to play NSBeep() from the Mac Catalyst environment? Thanks in advance to anyone who answers.
I'm having a hard time finding samples that clearly explain how to use WKContentRuleList objects. I read that WKContentRuleList use the same format as Safari content blocker extensions however when I try to compile a content blocker from the sample app AdoptingDeclarativeContentBlockingInSafariWebExtensions it complains about missing a "trigger". I get
Error Domain=WKErrorDomain Code=6 "(null)" UserInfo={NSHelpAnchor=Rule list compilation failed: Invalid trigger object.}
When I try to use the rules from the AdoptingDeclarativeContentBlockingInSafariWebExtensions sample project:
[
{
"id": 1,
"priority": 1,
"action": { "type": "block" },
"condition": {"regexFilter": ".*", "resourceTypes": [ "image" ] }
},
{
"id": 2,
"priority": 1,
"action": { "type": "allow" },
"condition": {"regexFilter": "wikipedia", "resourceTypes": [ "image" ] }
}
]
So if WKContentRuleList requires different keys/value pairs than Safari content blockers are those differences documented anywhere? I can't really find any good info on this.
Thanks in advance.
Is there a way to block certain embedded inline javascript elements using WKContentRuleList? For example
<script>
evilJavascriptHere
</script>
The documentation states that you can specify a url-filter but what about inline scripts?