gpt4 book ai didi

iphone - 当 NSAttributedString + NSString 发送到 UIActivityViewController 并选择邮件应用程序时,iOS 7 应用程序崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:47:27 24 4
gpt4 key购买 nike

我想确认以下功能是否受支持:

我有一个简单的应用程序,我试图将一个字符串数组发送到 UIActivityViewController。该数组包含一个属性字符串和一个常规字符串。当我单击共享按钮并打开邮件应用程序时,出现崩溃和错误。但是,当我仅单独发送属性字符串时,它会起作用。

我已经在 IOS6 上试过了,它运行良好。

配置如下:

 NSAttributedString *appName=[[NSAttributedString alloc] initWithString:@"TasteBank\n"     
attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:[UIFont
systemFontSize]],NSForegroundColorAttributeName:[UIColor brownColor]}];

//crash seen when @"test" added to array without that no crash when mail app opened on ios7

NSMutableArray *dataToShare = [[NSMutableArray alloc ] initWithObjects: appName, @"test", nil];

UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];

[self presentViewController:activityViewController animated:YES completion:^{}];

这有什么问题吗? IOS7支持这个配置吗?如果是这样,这可能是一个错误吗?

当我在装有 IOS 7 的 iPhone 4 上运行时,我看到以下错误:

2013-10-17 11:43:50.609 testing12[2499:60b] -[NSConcreteMutableAttributedString appendString:]:        unrecognized selector sent to instance 0x165ae670
2013-10-17 11:43:50.612 testing12[2499:60b] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableAttributedString appendString:]: unrecognized selector sent to instance 0x165ae670'
First throw call stack:
(0x2ff53f53 0x3a32c6af 0x2ff578e7 0x2ff561d3 0x2fea5598 0x32c389a1 0x328e2f2b 0x328e2bb1 0x328e2791 0x328e23b7 0x328e20dd 0x3284c101 0x3284c101 0x326f9601 0x326f468d 0x326c9a25 0x326c8221 0x2ff1f18b 0x2ff1e65b 0x2ff1ce4f 0x2fe87ce7 0x2fe87acb 0x34ba8283 0x32729a41 0xbd1ed 0x3a834ab7)

我在 XCODE 5 中的 IOS7.0 模拟器上运行时看到这个错误:

2013-10-17 11:23:42.054 testing12[3258:a0b] -[NSConcreteMutableAttributedString appendString:]: unrecognized selector sent to instance 0xa181470
2013-10-17 11:23:42.085 testing12[3258:a0b] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableAttributedString appendString:]: unrecognized selector sent to instance 0xa181470'
First throw call stack:
(0 CoreFoundation 0x017345e4 exceptionPreprocess + 180
1 libobjc.A.dylib 0x014b78b6 objc_exception_throw + 44
2 CoreFoundation 0x017d1903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172490b forwarding___ + 1019
4 CoreFoundation 0x017244ee _CF_forwarding_prep_0 + 14
5 UIKit 0x008bdfa3 -[UIMailActivity prepareWithActivityItems:] + 2346
6 UIKit 0x008b9242 -[UIActivityViewController _executeActivity] + 424
7 UIKit 0x008ba824 -[UIActivityViewController _performActivity:] + 1359
8 libobjc.A.dylib 0x014c981f -[NSObject performSelector:withObject:] + 70
9 UIKit 0x0063c75a -[UIActivityGroupViewController collectionView:didSelectItemAtIndexPath:] + 148
10 UIKit 0x0083929b -[UICollectionView _selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:] + 605
11 UIKit 0x008516d8 -[UICollectionView _userSelectItemAtIndexPath:] + 189
12 UIKit 0x00851895 -[UICollectionView touchesEnded:withEvent:] + 437
13 libobjc.A.dylib 0x014c9874 -[NSObject performSelector:withObject:withObject:] + 77
14 UIKit 0x00382f92 forwardTouchMethod + 271
15 UIKit 0x00383002 -[UIResponder touchesEnded:withEvent:] + 30
16 libobjc.A.dylib 0x014c9874 -[NSObject performSelector:withObject:withObject:] + 77
17 UIKit 0x00382f92 forwardTouchMethod + 271
18 UIKit 0x00383002 -[UIResponder touchesEnded:withEvent:] + 30
19 UIKit 0x0059dd7f _UIGestureRecognizerUpdate + 7166
20 UIKit 0x00268d4a -[UIWindow _sendGesturesForEvent:] + 1291
21 UIKit 0x00269c6a -[UIWindow sendEvent:] + 1030
22 UIKit 0x0023da36 -[UIApplication sendEvent:] + 242
23 UIKit 0x00227d9f _UIApplicationHandleEventQueue + 11421
24 CoreFoundation 0x016bd8af CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
25 CoreFoundation 0x016bd23b __CFRunLoopDoSources0 + 235
26 CoreFoundation 0x016da30e __CFRunLoopRun + 910
27 CoreFoundation 0x016d9b33 CFRunLoopRunSpecific + 467
28 CoreFoundation 0x016d994b CFRunLoopRunInMode + 123
29 GraphicsServices 0x036859d7 GSEventRunModal + 192
30 GraphicsServices 0x036857fe GSEventRun + 104
31 UIKit 0x0022a94b UIApplicationMain + 1225
32 testing12 0x00002efd main + 141
33 libdyld.dylib 0x01d70725 start + 0
34 ??? 0x00000001 0x0 + 1
)

最佳答案

我不知道这是否有帮助,但我用一个自定义事件提供程序解决了我的问题,该提供程序只将 NSString 提供给电子邮件类型,并将属性字符串提供给所有其他类型。电子邮件 Controller 自动检测到该字符串是 HTML 并正确格式化它。

我想如果您可以从 HTML 获得与您使用属性字符串相同的效果,这可能会有帮助吗?

@implementation ProductActivityItemProvider

...

- (id)placeholderItem {
return [[NSAttributedString alloc] initWithString:@""];
}

- (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType {

if ([activityType isEqualToString:UIActivityTypeMail])
return [NSString stringWithFormat:@"I shared %@", self.product.title];

return nil;
}

- (id)item {
NSString *raw = [NSString stringWithFormat:@"<html><body>%@<br />%@<br /><b>%@</b></body></html>",
self.product.designer,
self.product.title,
self.product.price];

// The mail controller will (a) autodetect HTML and (b) crash if it's given an attributed string. sigh.
if ([self.activityType isEqualToString:UIActivityTypeMail])
return raw;

NSData *data = [raw dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *options = @{
NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute : @(NSUTF8StringEncoding)
};

NSAttributedString *text = [[NSAttributedString alloc] initWithData:data
options:options
documentAttributes:nil
error:nil];
return text;
}

@end

关于iphone - 当 NSAttributedString + NSString 发送到 UIActivityViewController 并选择邮件应用程序时,iOS 7 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19435296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com