\u7f51\u9875\u6253\u5305\u6210APP<\/a>utputImage];<\/p>\n“`<\/p>\n
2. PDF\u6587\u6863\u751f\u6210<\/p>\n
\u5728iOS\u8bbe\u5907\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528Quartz 2D\u6846\u67b6\u4e2d\u7684CGPDFContextRef\u6765\u751f\u6210PDF\u6587\u6863\u3002\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n
“`<\/p>\n
\/\/\u83b7\u53d6\u6587\u6863\u5b58\u50a8\u8def\u5f84<\/p>\n
NSString *pdfPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@”example.pdf”];<\/p>\n
\/\/\u521b\u5efaPDF\u6587\u6863\u4e0a\u4e0b\u6587<\/p>\n
CFURLRef pdfURL = (__bridge CFURLRef)[NSURL fileURLWithPath:pdfPath];<\/p>\n
CGContextRef pdfContext = CGPDFContextCreateWithURL(pdfURL, NULL, NULL);<\/p>\n
\/\/\u5f00\u59cb\u7ed8\u5236PDF\u5185\u5bb9<\/p>\n
CGPDFContextBeginPage(pdfContext, NULL);<\/p>\n
\/\/\u7ed8\u5236\u6587\u672c<\/p>\n
CGContextSelectFont(pdfContext, “Helvetica”, 20, kCGEncodingMacRoman);<\/p>\n
CGContextSetTextDrawingMode(pdfContext, kCGTextFill);<\/p>\n
CGContextSetRGBFillColor(pdfContext, 0, 0, 0, 1);<\/p>\n
const char *text = “Hello, World!”;<\/p>\n
CGContextShowTextAtPoint(pdfContext, 50, 50, text, strlen(text));<\/p>\n
CGPDFContextEndPage(pdfContext);<\/p>\n
\/\/\u91ca\u653ePDF\u6587\u6863\u4e0a\u4e0b\u6587<\/p>\n
CGPDFContextClose(pdfContext);<\/p>\n
CFRelease(pdfContext);<\/p>\n
“`<\/p>\n
3. \u97f3\u9891\u6587\u4ef6\u751f\u6210<\/p>\n
\u5728iOS\u8bbe\u5907\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528AVFoundation\u6846\u67b6\u4e2d\u7684AVAssetWriter\u548cAVAssetWriterInput\u7c7b\u6765\u751f\u6210\u97f3\u9891\u6587\u4ef6\u3002\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n
“`<\/p>\n
\/\/\u521b\u5efa\u97f3\u9891\u6587\u4ef6\u8f93\u51fa\u8def\u5f84<\/p>\n
NSString *audioPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@”example.caf”];<\/p>\n
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];<\/p>\n
\/\/\u521b\u5efa\u97f3\u9891\u8f93\u5165\u6570\u636e\u683c\u5f0f<\/p>\n
NSDictionary *audioSettings = @{AVFormatIDKey: @(kAudioFormatAppleIMA4),<\/p>\n
AVSampleRateKey: @(44100.0),<\/p>\n
AVNumberOfChannelsKey: @(1)};<\/p>\n
\/\/\u521b\u5efa\u97f3\u9891\u6587\u4ef6\u8f93\u51fa<\/p>\n
NSError *error;<\/p>\n
AVAssetWriter *audioWriter = [[AVAssetWriter alloc] initWithURL:audioURL fileType:AVFileTypeCoreAudioFormat error:&error];<\/p>\n
if (error) {<\/p>\n
NSLog(@”\u97f3\u9891\u6587\u4ef6\u8f93\u51fa\u9519\u8bef\uff1a%@”, error.localizedDescription);<\/p>\n
return;<\/p>\n
}<\/p>\n
\/\/\u521b\u5efa\u97f3\u9891\u6587\u4ef6\u8f93\u5165<\/p>\n
AVAssetWriterInput *audioInput = [[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeAudio outputSettings:audioSettings];<\/p>\n
audioInput.expectsMediaDataInRealTime = YES;<\/p>\n
[audioWriter addInput:audioInput];<\/p>\n
\/\/\u5f00\u59cb\u5199\u5165\u97f3\u9891\u6570\u636e<\/p>\n
[audioWriter startWriting];<\/p>\n
[audioWriter startSessionAtSourceTime:kCMTimeZero];<\/p>\n
for (int i = 0; i <\/p>\n
\/\/\u751f\u6210\u97f3\u9891\u6570\u636e<\/p>\n
NSData *audioData = [self geneios\u5f00\u53d1\u5de5\u5177<\/a>rateAudioData];<\/p>\n CMSampleBufferRef sampleBuffer = [self createSampleBufferWithAudioData:audioData];<\/p>\n
\/\/\u5c06\u97f3\u9891\u6570\u636e\u5199\u5165\u6587\u4ef6<\/p>\n
if (audioInput.readyForMoreMediaData) {<\/p>\n
[audioInput appendSampleBuffer:sampleBuffer];<\/p>\n
}<\/p>\n
\/\/\u91ca\u653e\u97f3\u9891\u6570\u636e<\/p>\n
CFRelease(sampleBuffer);<\/p>\n
}<\/p>\n
[audioInput markAsFinished];<\/p>\n
[audioWriter endSessionAtSourceTime:CMTimeMake(1000, 44100)];<\/p>\n
[audioWriter finishWritingWithCompletionHandler:^{<\/p>\n
NSLog(@”\u97f3\u9891\u6587\u4ef6\u751f\u6210\u6210\u529f\uff01”);<\/p>\n
}];<\/p>\n
“`<\/p>\n
\u7efc\u4e0a\u6240\u8ff0\uff0ciOS\u751f\u6210\u662f\u4e00\u9879\u975e\u5e38\u91cd\u8981\u7684\u6280\u672f\uff0c\u5728\u5404\u4e2a\u9886\u57df\u90fd\u6709\u5e7f\u6cdb\u5e94\u7528\u3002\u901a\u8fc7\u8c03\u7528\u7cfb\u7edf\u63d0\u4f9b\u7684API\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u4e8c\u7ef4\u7801\u3001PDF\u6587\u6863\u3001\u97f3\u9891\u6587\u4ef6\u7b49\u7684\u751f\u6210\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
iOS\u751f\u6210\u662f\u6307\u5728iOS\u8bbe\u5907\u4e0a\u751f\u6210\u4e00\u4e9b\u7279\u5b9a\u7684\u6570\u636e\u6216\u6587\u4ef6\uff0c\u4f8b\u5982\u4e8c\u7ef4\u7801\u3001PDF\u6587\u6863\u3001\u97f3\u9891\u6587\u4ef6\u7b49\u7b49\u3002iOS\u751f\u6210\u7684\u539f\u7406\u662f\u901a\u8fc7\u8c03\u7528\u7cfb\u7edf\u63d0\u4f9b\u7684API\uff0c\u4f7f\u7528\u7279\u5b9a\u7684\u7b97\u6cd5\u548c\u6570\u636e\u5904\u7406\u65b9\u6cd5\u6765\u751f\u6210\u76f8\u5e94\u7684\u6570\u636e\u6216\u6587\u4ef6\u3002\u4e0b\u9762\u5c06\u5206\u522b<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2750,2345,95,588,2749],"class_list":["post-1252","post","type-post","status-publish","format-standard","hentry","category-zuoapp","tag-ipa","tag-2345","tag-95","tag-588","tag-2749"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=1252"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1252\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=1252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=1252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=1252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}