iOS
Add Nosmai Effects to a native iOS app: camera preview, beauty, makeup, color, filters, capture and recording.
Install
Install via CocoaPods. Add the pod to your Podfile and run pod install.
pod 'NosmaiCameraSDK', :git => 'https://github.com/nosmai/camera-sdk-ios.git'
Requirements: iOS 12.0+, iPhone 8 or newer, Xcode 13.0+. In Info.plist add:
<key>NSCameraUsageDescription</key>
<string>Camera access for filters and effects</string>
<key>NSMicrophoneUsageDescription</key>
<string>Microphone access for video recording</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Save photos and videos to your gallery</string>
The examples below are Objective-C. The SDK also imports into Swift (import NosmaiCameraSDK); the method names follow the standard Swift bridging.
Initialize
Initialize once at startup, for example in your app delegate.
#import <NosmaiCameraSDK/NosmaiSDK.h>
[[NosmaiSDK shared] initWithLicenseKey:@"YOUR_LICENSE_KEY"];
BOOL ready = [[NosmaiSDK shared] isInitialized];
Camera preview
#import <NosmaiCameraSDK/NosmaiCamera.h>
self.camera = [[NosmaiCamera alloc] init];
[self.camera setupPreviewInView:self.previewView];
[self.camera startCamera];
// later
[self.camera stopCamera];
Camera controls
[self.camera switchCamera]; // front / back
[self.camera setFlashMode:NosmaiFlashModeOn]; // photo flash
[self.camera setTorchMode:NosmaiTorchModeOn]; // continuous torch
BOOL hasFlash = [self.camera hasFlash];
BOOL hasTorch = [self.camera hasTorch];
Beauty and makeup
Intensities are 0.0 to 1.0 unless noted.
[self.camera applySkinSmoothing:0.7f];
[self.camera applySkinWhitening:0.5f];
[self.camera applyFaceSlimming:0.3f];
[self.camera applyEyeEnlargement:0.4f];
[self.camera applyNoseAdjustment:-0.2f]; // -1.0 to 1.0
[self.camera applyLipstick:0.6f];
[self.camera applyBlusher:0.4f];
Color adjustments
[self.camera applyBrightness:0.2f]; // -1.0 to 1.0
[self.camera applyContrast:1.2f]; // 0.0 to 2.0
[self.camera applySaturation:1.1f]; // 0.0 to 2.0
[self.camera applyRGBWithRed:1.1f green:0.9f blue:1.0f];
[self.camera applyHSBWithHue:15.0f saturation:1.1f brightness:0.1f];
Filters
Use NosmaiCore.shared.effects to list filters and download cloud filters. Apply a filter by path or name.
Local filters. Add a filters folder of .nosmai files to your app target (use “Create folder references” so the folder is preserved), then:
[[NosmaiCore shared].effects getLocalFilters:^(NSArray<NSDictionary *> *filters) {
for (NSDictionary *filter in filters) {
NSString *name = filter[@"name"]; // file name without extension
NSString *path = filter[@"path"]; // e.g. "filters/vintage.nosmai"
}
}];
[self.camera applyFilter:@"filters/vintage.nosmai"];
[self.camera removeAllFilters];
All filters (local and cloud).
[[NosmaiCore shared].effects getFilters:^(NSArray<NSDictionary *> *filters, NSError *error) {
for (NSDictionary *filter in filters) {
NSString *type = filter[@"type"]; // "local" or "cloud"
NSString *filterType = filter[@"filterType"]; // "filter" or "effect"
}
}];
Download a cloud filter, then apply it.
[[NosmaiCore shared].effects downloadCloudFilter:@"halloween_2024"
progress:^(float progress) {
// 0.0 to 1.0
}
completion:^(BOOL success, NSString *localPath, NSError *error) {
if (success) [self.camera applyFilter:localPath];
}];
Effect parameters. Some effects expose adjustable parameters.
NSArray *params = [[NosmaiCore shared].effects getEffectParameters];
[self.camera setFilterParameter:@"intensity" value:@(0.8f)];
Capture and recording
[self.camera capturePhotoWithCompletion:^(UIImage *image, NSError *error) {
if (image) { /* save or display */ }
}];
[self.camera startRecording];
[self.camera stopRecordingWithCompletion:^(NSURL *videoURL, NSError *error) {
if (videoURL) { /* save or share */ }
}];
Error handling
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNosmaiError:)
name:@"NosmaiErrorNotification" object:nil];
- (void)handleNosmaiError:(NSNotification *)note {
NSError *error = note.userInfo[@"error"];
}
NOTE
Run effects on a physical device. The camera is required, and the simulator does not provide a camera feed.