I'm running Xcode 12.4, testing on iOS 13 and 14.
How can a user be logged in/iCloud Available, but still Not Authenticated?
When I fetch a record, the CKErrorCode is NotAuthenticated and it prints Couldn't get an authentication token
let predicate = NSPredicate(format: "id == %@", id)
let query = CKQuery(recordType: RecordType.Media, predicate: predicate)
CKContainer.default().publicCloudDatabase.perform(query, inZoneWith: nil) { (ckRecords, error) in
if let err = error {
let code = err._code
// error code is 9 - case NotAuthenticated /* Not authenticated (writing without being logged in, no user record) */
return
}
// ...
}
But when I check to see if the user is logged in, I use the code below, and in both situations it prints iCloud Available
1-
if FileManager.default.ubiquityIdentityToken != nil {
print("iCloud Available")
} else {
print("iCloud Unavailable")
}
2-
CKContainer.default().accountStatus { (accountStatus, error) in
switch accountStatus {
case .available:
print("iCloud Available")
case .noAccount:
print("No iCloud account")
case .restricted:
print("iCloud restricted")
case .couldNotDetermine:
print("Unable to determine iCloud status")
@unknown default:
print("Unable to determine iCloud status")
}
}
FYI, this seems to happen in this order.
1- I'm home on wiFi, logged into iCloud, everything works fine.
2- I leave my house, switch to a hot spot, I'm still logged into iCloud and everything works fine
3- I come back into my house, switch back to wiFi, of course I'm still logged in, then the above issue occurs. It's as if it wants me to log in again even though I'm already logged in and it says iCloud Available.
This issue is happening on both the real device and the simulator.
UPDATE
I just found this post, it seems lots of devs are having this same problem
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I've been able to center the middle of a 16:9 landscape video, crop the video, and then create a 9:16 portrait version of the video similar to how Apple does it in the Photos album.
The only issue is the resulting portrait video isn't centered in the middle of the screen (images below).
How can I get the resulting portrait video in the center of the screen?
func createExportSession(for videoURL: URL) {
let asset = AVURLAsset(url: videoURL)
let exporter = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality)!
exporter.videoComposition = turnHorizontalVideoToPortraitVideo(asset: asset)
exporter.outputURL = // ...
exporter.outputFileType = AVFileType.mp4
exporter.shouldOptimizeForNetworkUse = true
exporter.exportAsynchronously { [weak self] in
// ...
// the exporter.url is eventually added to an AVURLAsset and played inside an AVPlayer
}
}
func turnHorizontalVideoToPortraitVideo(asset: AVURLAsset) -> AVVideoComposition {
let track = asset.tracks(withMediaType: AVMediaType.video)[0]
let renderSize = CGSize(width: 720, height: 1280)
var transform1 = track.preferredTransform
transform1 = transform1.concatenating(CGAffineTransform(rotationAngle: CGFloat(90.0 * .pi / 180)))
transform1 = transform1.concatenating(CGAffineTransform(translationX: track.naturalSize.width, y: 0))
let transform2 = CGAffineTransform(translationX: track.naturalSize.height, y: (track.naturalSize.width - track.naturalSize.height) / 2)
let transform3 = transform2.rotated(by: CGFloat(Double.pi/2)).concatenating(transform1)
let translate = CGAffineTransform(translationX: renderSize.width, y: renderSize.height)
let rotateFromUpsideDown = translate.rotated(by: CGFloat(Double.pi)) // without this the portrait video is always upside down
let finalTransform = transform3.concatenating(rotateFromUpsideDown)
let transformer = AVMutableVideoCompositionLayerInstruction(assetTrack: track)
transformer.setTransform(finalTransform, at: .zero)
let instruction = AVMutableVideoCompositionInstruction()
instruction.timeRange = CMTimeRange(start: .zero, duration: asset.duration)
instruction.layerInstructions = [transformer]
let videoComposition = AVMutableVideoComposition()
videoComposition.frameDuration = CMTime(value: 1, timescale: 30)
videoComposition.renderSize = renderSize
videoComposition.instructions = [instruction]
return videoComposition
}
Initial horizontal video:
Resulting portrait video after running the above code. The portrait video is incorrectly centered:
This is the way that it should be centered: