MFMailComposeController를 사용하여 전자 메일에 첨부 파일로 키 저장을 보냅니다. 전자 메일 첨부 파일을 읽는 내 응용 프로그램은 키 보관 파일을 가져 오지만 저장을 해제하면 은 값이됩니다. 상세는 다음과 같이 :MFMailComposeController를 통해 전송 한 후 NSKeyedUnarchiver 결과가 nil 값이됩니다.
송신 뷰 컨트롤러 :
배열은 (NRCEventItem 배열)을 전송하기 전에 보관되는- (IBAction)saveAndSend:(id)sender {
// Email Subject
NSString *emailTitle = @"Test Email";
// Email Content
NSString *messageBody = @"TimeChime Trace Data";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@"[email protected]"];
if (![MFMailComposeViewController canSendMail]) {
NSLog(@"Mail services are not available.");
return;
}
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
// attach NSData to message. Note: file name extension will be used by the mail client to launch
// the handler with this extension in its info.plist.
NSData *data = [[NSData alloc]init];
data = [NSKeyedArchiver archivedDataWithRootObject:self.items];
[mc addAttachmentData:data mimeType:@"application/CustomUTIHandler" fileName:@"traceData.nrc"];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
}
:
Printing description of self->_items:
<__NSArrayM 0x1c045e390>(
Event Date/time: 2017-12-29 00:08:17 +0000, Event Sender: <AppDelegate: 0x1c40523c0>, Event Description: appl did become active,
Event Date/time: 2017-12-29 00:15:32 +0000, Event Sender: <HourlyChimeTableViewController: 0x10282fa00>, Event Description: triggerNotification,
Event Date/time: 2017-12-29 00:30:32 +0000, Event Sender: <HourlyChimeTableViewController: 0x10282fa00>, Event Description: triggerNotification,
Event Date/time: 2017-12-29 00:45:32 +0000, Event Sender: <HourlyChimeTableViewController: 0x10282fa00>, Event Description: triggerNotification,
Event Date/time: 2018-01-05 00:00:32 +0000, Event Sender: <HourlyChimeTableViewController: 0x10282fa00>, Event Description: triggerNotification,
Event Date/time: 2018-01-05 00:15:32 +0000, Event Sender: <HourlyChimeTableViewController: 0x10282fa00>, Event Description: triggerNotification,
Event Date/time: 2018-01-05 00:30:32 +0000, Event Sender: <HourlyChimeTableViewController: 0x10282fa00>, Event Description: triggerNotification,
Event Date/time: 2018-01-05 00:45:32 +0000, Event Sender: <HourlyChimeTableViewController: 0x10282fa00>, Event Description: triggerNotification
)
EventItem 클래스 NSCoding 따르는 :
//
// NRCEventItem.h
// Hourly Chime2
//
// Created by Nelson Capes on 12/12/17.
// Copyright © 2017 Nelson Capes. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NRCEventItem : NSObject <NSCoding>
@property (nonatomic) NSDate *eventDateTime;
@property (nonatomic) NSString *eventSender;
@property (nonatomic) NSString *eventDescription;
@end
을
수신 앱의 정보 목록 :
데이터를 전자 메일 첨부 파일을 가져 와서 전개함으로써 수신 응용 프로그램의 코드 :
- (void) receiveNotificationFromAppDelegate:(NSNotification *) notification {
NSLog(@"userInfo trace %@",notification.userInfo[KTraceKey]);
self.items = (NSMutableArray*)[NSKeyedUnarchiver unarchiveObjectWithData:notification.userInfo[KTraceKey]];
[self.tableView reloadData];
}
데이터 아카이브 해제 된 후에 : 분명히
Printing description of path:
/private/var/mobile/Containers/Data/Application/CCDA0B96-8DD6-496E-B0A0-08B3C072E76A/Documents/Inbox/traceData-40.nrc
Printing description of items:
<__NSArrayM 0x1c4240720>(
Event Date/time: (null), Event Sender: (null), Event Description: (null),
Event Date/time: (null), Event Sender: (null), Event Description: (null),
Event Date/time: (null), Event Sender: (null), Event Description: (null),
Event Date/time: (null), Event Sender: (null), Event Description: (null),
Event Date/time: (null), Event Sender: (null), Event Description: (null),
Event Date/time: (null), Event Sender: (null), Event Description: (null),
Event Date/time: (null), Event Sender: (null), Event Description: (null),
Event Date/time: (null), Event Sender: (null), Event Description: (null)
)
을의 NSKeyedUnarchiver가 인식 데이터를 배열로 간주하고 배열의 요소는 NRCEventItem입니다. 그러나 배열의 각 요소에있는 속성은 nil입니다. 또한 아카이브를 즉시 아카이브 해제하여 아카이브 단계를 테스트했으며 배열의 특성은 아카이브되기 전과 같습니다.
결론 : 어떻게 든 데이터는 MFMailComposeViewController를 사용하여 전송 중에 변경됩니다.
누구든지이 문제에 관해 밝힐 수 있다면 정말 고맙겠습니다.
NSCoding 프로토콜을 구현하는 비용을 포함 할 수 있습니까?같은 앱에서 왕복 여행을 해봤습니까? 그게 효과가 있니? NSData는 다른 끝에서 다르게 보입니까? –