Skip to content

Commit

Permalink
udpate swiftui demo
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Nov 13, 2023
1 parent 0d8a7f4 commit 957383c
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 111 deletions.
2 changes: 1 addition & 1 deletion Demo/Demo.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@
<array>
<string>audio</string>
<string>fetch</string>
<string>remote-notification</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
AC77DFB026402327001351AE /* TracyApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracyApp.swift; sourceTree = "<group>"; };
AC77DFB126402327001351AE /* URLImportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLImportView.swift; sourceTree = "<group>"; };
AC77DFB226402329001351AE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
AC77DFB726402329001351AE /* TracyPlayer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TracyPlayer.app; sourceTree = BUILT_PRODUCTS_DIR; };
AC77DFB726402329001351AE /* Player.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Player.app; sourceTree = BUILT_PRODUCTS_DIR; };
ACADA07528EDC067001B76D1 /* TracyPlayer.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TracyPlayer.entitlements; sourceTree = "<group>"; };
ACB965462A42EDCD00378A4C /* SettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = "<group>"; };
ACD2F747275F6E860006D16F /* KSPlayer */ = {isa = PBXFileReference; lastKnownFileType = folder; name = KSPlayer; path = ../..; sourceTree = "<group>"; };
ACD786482A6A8648004A0220 /* Defaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Defaults.swift; sourceTree = "<group>"; };
ACE3619328EB689F00F234EB /* TracyPlayer-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "TracyPlayer-Info.plist"; sourceTree = "<group>"; };
ACE3619328EB689F00F234EB /* Player-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Player-Info.plist"; sourceTree = "<group>"; };
ACEA9FEA298BFC8800FBA74B /* MovieModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieModel.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -59,7 +59,7 @@
isa = PBXGroup;
children = (
ACADA07528EDC067001B76D1 /* TracyPlayer.entitlements */,
ACE3619328EB689F00F234EB /* TracyPlayer-Info.plist */,
ACE3619328EB689F00F234EB /* Player-Info.plist */,
ACD2F743275F6D7A0006D16F /* Packages */,
AC77DFAF26402327001351AE /* Shared */,
AC77DFB826402329001351AE /* Products */,
Expand Down Expand Up @@ -92,7 +92,7 @@
AC77DFB826402329001351AE /* Products */ = {
isa = PBXGroup;
children = (
AC77DFB726402329001351AE /* TracyPlayer.app */,
AC77DFB726402329001351AE /* Player.app */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -123,9 +123,9 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
AC77DFB626402329001351AE /* TracyPlayer */ = {
AC77DFB626402329001351AE /* Player */ = {
isa = PBXNativeTarget;
buildConfigurationList = AC77DFCB26402329001351AE /* Build configuration list for PBXNativeTarget "TracyPlayer" */;
buildConfigurationList = AC77DFCB26402329001351AE /* Build configuration list for PBXNativeTarget "Player" */;
buildPhases = (
AC77DFB326402329001351AE /* Sources */,
AC77DFB426402329001351AE /* Frameworks */,
Expand All @@ -135,12 +135,12 @@
);
dependencies = (
);
name = TracyPlayer;
name = Player;
packageProductDependencies = (
ACD2F771275F735C0006D16F /* KSPlayer */,
);
productName = "demo-SPM (iOS)";
productReference = AC77DFB726402329001351AE /* TracyPlayer.app */;
productReference = AC77DFB726402329001351AE /* Player.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
Expand All @@ -158,7 +158,7 @@
};
};
};
buildConfigurationList = AC77DFAE26402327001351AE /* Build configuration list for PBXProject "TracyPlayer" */;
buildConfigurationList = AC77DFAE26402327001351AE /* Build configuration list for PBXProject "Player" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = en;
hasScannedForEncodings = 0;
Expand All @@ -171,7 +171,7 @@
projectDirPath = "";
projectRoot = "";
targets = (
AC77DFB626402329001351AE /* TracyPlayer */,
AC77DFB626402329001351AE /* Player */,
);
};
/* End PBXProject section */
Expand Down Expand Up @@ -356,7 +356,7 @@
ENABLE_HARDENED_RUNTIME = YES;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "TracyPlayer-Info.plist";
INFOPLIST_FILE = "Player-Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.video";
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
INFOPLIST_KEY_UILaunchStoryboardName = " ";
Expand All @@ -369,7 +369,8 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.1.2;
PRODUCT_BUNDLE_IDENTIFIER = com.kintan.tracy;
PRODUCT_BUNDLE_IDENTIFIER = com.kintan.player;
PRODUCT_NAME = Player;
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx xros xrsimulator";
Expand Down Expand Up @@ -398,7 +399,7 @@
ENABLE_HARDENED_RUNTIME = YES;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "TracyPlayer-Info.plist";
INFOPLIST_FILE = "Player-Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.video";
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
INFOPLIST_KEY_UILaunchStoryboardName = " ";
Expand All @@ -411,7 +412,8 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.1.2;
PRODUCT_BUNDLE_IDENTIFIER = com.kintan.tracy;
PRODUCT_BUNDLE_IDENTIFIER = com.kintan.player;
PRODUCT_NAME = Player;
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx xros xrsimulator";
Expand All @@ -428,7 +430,7 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
AC77DFAE26402327001351AE /* Build configuration list for PBXProject "TracyPlayer" */ = {
AC77DFAE26402327001351AE /* Build configuration list for PBXProject "Player" */ = {
isa = XCConfigurationList;
buildConfigurations = (
AC77DFC926402329001351AE /* Debug */,
Expand All @@ -437,7 +439,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
AC77DFCB26402329001351AE /* Build configuration list for PBXNativeTarget "TracyPlayer" */ = {
AC77DFCB26402329001351AE /* Build configuration list for PBXNativeTarget "Player" */ = {
isa = XCConfigurationList;
buildConfigurations = (
AC77DFCC26402329001351AE /* Debug */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.3">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand All @@ -15,9 +15,9 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AC77DFB626402329001351AE"
BuildableName = "TracyPlayer.app"
BlueprintName = "TracyPlayer"
ReferencedContainer = "container:TracyPlayer.xcodeproj">
BuildableName = "Player.app"
BlueprintName = "Player"
ReferencedContainer = "container:Player.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand All @@ -26,16 +26,13 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/../../FFmpegKit/.Script/LLDBInitFile"
enableASanStackUseAfterReturn = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand All @@ -47,17 +44,11 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AC77DFB626402329001351AE"
BuildableName = "TracyPlayer.app"
BlueprintName = "TracyPlayer"
ReferencedContainer = "container:TracyPlayer.xcodeproj">
BuildableName = "Player.app"
BlueprintName = "Player"
ReferencedContainer = "container:Player.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-com.apple.CoreData.ConcurrencyDebug 1"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -70,9 +61,9 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AC77DFB626402329001351AE"
BuildableName = "TracyPlayer.app"
BlueprintName = "TracyPlayer"
ReferencedContainer = "container:TracyPlayer.xcodeproj">
BuildableName = "Player.app"
BlueprintName = "Player"
ReferencedContainer = "container:Player.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
Expand Down
12 changes: 2 additions & 10 deletions Demo/SwiftUI/Shared/MovieModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,8 @@ extension MovieModel {
return playmodel
}
let model = PlayModel()
guard let context = managedObjectContext, let privateStore = PersistenceController.shared.privateStore else {
return model
}
let newMovieModel = MovieModel(context: context)
newMovieModel.setValuesForKeys(dictionaryWithValues(forKeys: entity.attributesByName.keys.map { $0 }))
newMovieModel.playmodel = model
context.assign(newMovieModel, to: privateStore)
// try? context.save()
newMovieModel.save()
context.delete(self)
playmodel = model
model.save()
return model
}
}
Expand Down
55 changes: 2 additions & 53 deletions Demo/SwiftUI/Shared/Persistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ struct PersistenceController {

let container: NSPersistentCloudKitContainer
let viewContext: NSManagedObjectContext
let privateStore: NSPersistentStore?
init(inMemory: Bool = false) {
let modelName = "Model"
// load Data Model
Expand All @@ -59,39 +58,9 @@ struct PersistenceController {
}
container = NSPersistentCloudKitContainer(name: modelName, managedObjectModel: model)
viewContext = container.viewContext
// viewContext = container.newBackgroundContext()
let publicURL: URL
let privateURL: URL
let localURL: URL
if inMemory {
publicURL = URL(fileURLWithPath: "/dev/null")
privateURL = URL(fileURLWithPath: "/dev/null")
localURL = URL(fileURLWithPath: "/dev/null")

} else {
let directory = NSPersistentContainer.defaultDirectoryURL()
KSLog("coreData directory \(directory)")
publicURL = directory.appendingPathComponent("public.sqlite")
privateURL = directory.appendingPathComponent("private.sqlite")
localURL = directory.appendingPathComponent("local.sqlite")
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}
let publicDesc = NSPersistentStoreDescription(url: publicURL)
publicDesc.configuration = "public"
publicDesc.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.TracyPlayer")
publicDesc.cloudKitContainerOptions?.databaseScope = .public
publicDesc.setOption(true as NSObject, forKey: NSPersistentHistoryTrackingKey)
publicDesc.setOption(true as NSObject, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
let privateDesc = NSPersistentStoreDescription(url: privateURL)
privateDesc.configuration = "private"
privateDesc.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.TracyPlayer")
privateDesc.setOption(true as NSObject, forKey: NSPersistentHistoryTrackingKey)
privateDesc.setOption(true as NSObject, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
let localDesc = NSPersistentStoreDescription(url: localURL)
localDesc.configuration = "local"
localDesc.setOption(true as NSObject, forKey: NSPersistentHistoryTrackingKey)
localDesc.setOption(true as NSObject, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
container.persistentStoreDescriptions = [localDesc, privateDesc, publicDesc]
// let persistentStoreCoordinator = container.persistentStoreCoordinator
container.loadPersistentStores { storeDescription, error in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
Expand All @@ -112,26 +81,6 @@ struct PersistenceController {
// }
}
}
privateStore = container.persistentStoreCoordinator.persistentStore(for: privateURL)
let viewContext = container.newBackgroundContext()
viewContext.automaticallyMergesChangesFromParent = true
viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
// #if DEBUG
// viewContext.mergePolicy = NSOverwriteMergePolicy
// #endif
viewContext.perform {
do {
try viewContext.setQueryGenerationFrom(.current)
} catch {
fatalError("Failed to pin viewContext to the current generation:\(error)")
}
}
// let privateContainer = NSPersistentCloudKitContainer(name: modelName, managedObjectModel: model)
// privateContainer.persistentStoreDescriptions = [privateDesc]
// privateContainer.loadPersistentStores { _, _ in
// }
// privateContainer.viewContext.automaticallyMergesChangesFromParent = true
// privateContainer.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
// try? privateContainer.viewContext.setQueryGenerationFrom(.current)
container.viewContext.automaticallyMergesChangesFromParent = true
}
}
10 changes: 2 additions & 8 deletions Demo/SwiftUI/TracyPlayer.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
<key>com.apple.developer.aps-environment</key>
<string>development</string>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.TracyPlayer</string>
</array>
<array/>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudKit</string>
</array>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>
<array/>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.assets.movies.read-write</key>
Expand Down
2 changes: 1 addition & 1 deletion FFmpegKit
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var ffmpegKitPath = FileManager.default.currentDirectoryPath + "/FFmpegKit"
if !FileManager.default.fileExists(atPath: ffmpegKitPath) {
ffmpegKitPath = FileManager.default.currentDirectoryPath + "/KSPlayer/FFmpegKit"
}

if !FileManager.default.fileExists(atPath: ffmpegKitPath), let url = URL(string: #file) {
let path = url.deletingLastPathComponent().path
// 解决用xcode引入spm的时候,依赖关系出错的问题
Expand Down
1 change: 1 addition & 0 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var ffmpegKitPath = FileManager.default.currentDirectoryPath + "/FFmpegKit"
if !FileManager.default.fileExists(atPath: ffmpegKitPath) {
ffmpegKitPath = FileManager.default.currentDirectoryPath + "/KSPlayer/FFmpegKit"
}

if !FileManager.default.fileExists(atPath: ffmpegKitPath), let url = URL(string: #file) {
let path = url.deletingLastPathComponent().path
// 解决用xcode引入spm的时候,依赖关系出错的问题
Expand Down

0 comments on commit 957383c

Please sign in to comment.