Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ private let sharedSecretKey = "secret_key"
3. **Configure Privacy Settings**: If you are adding this wrapper to an existing project, ensure that you add the following keys to your Info.plist:

```
Privacy - Photo Library Usage Description
Privacy - Camera Usage Description
```

Expand Down
6 changes: 0 additions & 6 deletions SwiftUI-AI-Wrapper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
318DAF612C3BA56A00619995 /* InputMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 318DAF602C3BA56A00619995 /* InputMessageView.swift */; };
318DAF632C3BA5C600619995 /* ConnectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 318DAF622C3BA5C600619995 /* ConnectionRequest.swift */; };
318DAF652C3BA5FA00619995 /* DateExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 318DAF642C3BA5FA00619995 /* DateExtensions.swift */; };
318DAF672C3BA62900619995 /* PhotoPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 318DAF662C3BA62900619995 /* PhotoPicker.swift */; };
318DAF6B2C3CDE0100619995 /* StringHash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 318DAF6A2C3CDE0100619995 /* StringHash.swift */; };
/* End PBXBuildFile section */

Expand All @@ -45,7 +44,6 @@
318DAF602C3BA56A00619995 /* InputMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputMessageView.swift; sourceTree = "<group>"; };
318DAF622C3BA5C600619995 /* ConnectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionRequest.swift; sourceTree = "<group>"; };
318DAF642C3BA5FA00619995 /* DateExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateExtensions.swift; sourceTree = "<group>"; };
318DAF662C3BA62900619995 /* PhotoPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoPicker.swift; sourceTree = "<group>"; };
318DAF6A2C3CDE0100619995 /* StringHash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringHash.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -83,7 +81,6 @@
318DAF3E2C3BA1E900619995 /* ContentView.swift */,
318DAF502C3BA2DE00619995 /* HistoryView.swift */,
318DAF4A2C3BA22400619995 /* CameraView.swift */,
318DAF662C3BA62900619995 /* PhotoPicker.swift */,
318DAF5C2C3BA42800619995 /* PhotoView.swift */,
318DAF522C3BA2EF00619995 /* Models */,
318DAF682C3BADFE00619995 /* ChatViews */,
Expand Down Expand Up @@ -212,7 +209,6 @@
318DAF6B2C3CDE0100619995 /* StringHash.swift in Sources */,
318DAF612C3BA56A00619995 /* InputMessageView.swift in Sources */,
318DAF652C3BA5FA00619995 /* DateExtensions.swift in Sources */,
318DAF672C3BA62900619995 /* PhotoPicker.swift in Sources */,
318DAF3F2C3BA1E900619995 /* ContentView.swift in Sources */,
318DAF5D2C3BA42800619995 /* PhotoView.swift in Sources */,
318DAF3D2C3BA1E900619995 /* SwiftUI_AI_WrapperApp.swift in Sources */,
Expand Down Expand Up @@ -356,7 +352,6 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSCameraUsageDescription = "Access to your camera is required to take photos of objects";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Permission required to upload photos to the AI Wrapper";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down Expand Up @@ -387,7 +382,6 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSCameraUsageDescription = "Access to your camera is required to take photos of objects";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Permission required to upload photos to the AI Wrapper";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down
39 changes: 34 additions & 5 deletions SwiftUI-AI-Wrapper/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import SwiftUI
import AVFoundation
import PhotosUI

struct CameraView: View {

Expand All @@ -32,6 +33,7 @@ struct CameraView: View {
//@State private var imagePickerOpacity: CGFloat = 0
@State private var selectedImage: UIImage? = nil
@State private var filename: String? = nil
@State private var selectedItem: PhotosPickerItem?

@Binding var showHistory: Bool

Expand Down Expand Up @@ -158,10 +160,7 @@ struct CameraView: View {
.padding(25)
}
.foregroundColor(.white)
.sheet(isPresented: $showImagePicker) {
PhotoPicker(isPresented: $showImagePicker, selectedImage: $selectedImage, filename: $filename)
.accentColor(.blue)
}
.photosPicker(isPresented: $showImagePicker, selection: $selectedItem, matching: .images)

Spacer()
Button(action: {
Expand Down Expand Up @@ -250,6 +249,11 @@ struct CameraView: View {
}
}
}
.onChange(of: selectedItem) { newItem in
if let item = newItem {
handleSelection(item: item)
}
}
.edgesIgnoringSafeArea(.all)
}

Expand Down Expand Up @@ -316,7 +320,32 @@ struct CameraView: View {
}
}


// Handles the selected photo, extracting the image and filename.
private func handleSelection(item: PhotosPickerItem) {
// Load the image as a UIImage
item.loadTransferable(type: Data.self) { result in
DispatchQueue.main.async {
switch result {
case .success(let data):
if let data = data, let image = UIImage(data: data) {
self.selectedImage = image
}
case .failure(let error):
self.selectedItem = nil
print("Error loading image: \(error.localizedDescription)")
}
}
}

// Retrieve the filename (if available)
if let assetIdentifier = item.itemIdentifier {
let asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetIdentifier], options: nil).firstObject
filename = asset?.value(forKey: "filename") as? String
}

// Clear CameraRoll item selection
selectedItem = nil
}
}


Expand Down
103 changes: 0 additions & 103 deletions SwiftUI-AI-Wrapper/PhotoPicker.swift

This file was deleted.