我有一个mpmovieplayer控制器播放在线音乐和avaudiosession在背景播放相同的音乐,当第一次应用程序启动没有网络访问,通常我显示"没有互联网连接",当我尝试连接到互联网并播放后显示错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'
Run Code Online (Sandbox Code Playgroud)
我的代码在这里
static MPMoviePlayerController *player=nil;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
[MainViewController stopStreaming];
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://159.253.145.180:7104"]];
player.movieSourceType = MPMovieSourceTypeStreaming;
player.view.hidden = YES;
[self.view addSubview:player.view];
[player prepareToPlay];
[player play];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSError *setCategoryErr = nil;
NSError *activationErr = nil; …Run Code Online (Sandbox Code Playgroud) 我对这段代码感到很疯狂,它应该可以工作,但是当我收到邮件时没有附加文件,这是我的代码:
-(IBAction)mandar:(id)sender
{
MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail])
{
[composer setToRecipients:[NSArray arrayWithObjects:@"tuperroensalsa@hotmail.com",nil]];
[composer setSubject:@"Base de datos"];
[composer setMessageBody:@"Mensage" isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];
NSString *path = [[NSString alloc] initWithFormat:@"%@/capturas.sqlite",documentPath];
NSString *Newpath = [[NSString alloc] initWithFormat:@"%@/newData.sqlite",documentPath];
[[NSFileManager defaultManager] copyItemAtPath:path toPath:Newpath error:nil];
NSData *data = [NSData dataWithContentsOfFile:Newpath];
[composer addAttachmentData:data mimeType:@"application/x-sqlite3" fileName:@"capturas.sqlite"];
[self presentModalViewController:composer animated:YES];
}
else {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error" message:@"No se a podido mandar el mensage" delegate:self cancelButtonTitle:@"dismis" …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我正在加载HTML字符串,该字符串是从json文件解析的,字符串已经包含字体颜色和字体大小,但我需要更改字体的颜色和大小.要替换它我已经使用了以下代码,但它不起作用
NSString *webString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'",
textFontSize];
[web stringByEvaluatingJavaScriptFromString:webString];
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以改变它.如果是的话,请告诉我答案.
特殊字符将在标签上用红色突出显示,因此我在下面编写了功能不错的函数,但我想确认一下,还有其他有效的方法吗?例如
-(NSMutableAttributedString*)getAttributeText:(NSString*)string forSubstring:(NSString*)searchstring {
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:_lblName.text];
NSRange searchRange = NSMakeRange(0,string.length);
for (NSInteger charIdx=0; charIdx<searchstring.length; charIdx++){
NSString *substring = [searchstring substringWithRange:NSMakeRange(charIdx, 1)];
NSRange foundRange;
searchRange.location = 0;
while (searchRange.location < string.length) {
searchRange.length = string.length-searchRange.location;
foundRange = [string rangeOfString:substring options:1 range:searchRange];
[text addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range:foundRange];
if (foundRange.location != NSNotFound) {
searchRange.location = foundRange.location+foundRange.length;
} else {
// no more substring to find
break;
}
}
}
return text;
}
Run Code Online (Sandbox Code Playgroud)
下面是我如何使用它的代码,以及结果
NSString *string = @"James …Run Code Online (Sandbox Code Playgroud) iphone objective-c processing-efficiency nsattributedstring ios
我正在使用图像,我有很多它们,而且我正在从服务器上实时下载它们,然后才真正快速地使用AsyncImageView类,但是我知道我正在使用自定义类,UIImage而不是UIImageView.
问题:转换UIImageView为有什么好方法UIImage吗?
提前致谢!
我想通过iphone中的电子邮件发送扩展名为.caf的音频文件.任何人都可以帮我这样做吗?我写过,mimeType:@"audio/caf"但我认为不支持.请帮我做这个小任务.
我使用MFMailComposeViewController发送电子邮件,
使用此代码,我可以获取图像,但图像来自文本详细信息,我不是第一个图像和文本之后,
这是我的代码,
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
//Setting up the Subject, recipients, and message body.
[mail setToRecipients:[NSArray arrayWithObjects:Emailid,nil]];
[mail setSubject:@"Receipt"];
NSData *photoData = UIImageJPEGRepresentation([UIImage imageNamed:@"Gift.png"], 1);
[mail addAttachmentData:photoData mimeType:@"image/jpg" fileName:[NSString stringWithFormat:@"photo.png"]];
[mail setMessageBody:@"Receipt" isHTML:NO];
NSString *emailBody;
emailBody = [NSString stringWithFormat:@
"<br>Purchase Amount: </br> " "$ %@"
"<br>Amount Received: </br> " "$ %@"
"<br>Change: </br> " "$ %@"
,AmountData,txtAmount.text,ChangeAmount.text];
[mail setMessageBody:emailBody isHTML:YES];
Run Code Online (Sandbox Code Playgroud)
请任何人建议我怎么办?
iphone cocoa-touch objective-c ios4 mfmailcomposeviewcontroller
我想显示一系列图像,如:

任何人都可以让我知道,有没有API,我可以通过它显示图像,如演示图像所示?
我有一个包含NSDictionary列表的NSArray.喜欢:
NSArray *array = ...;
NSDictionary *item = [array objectAtIndex:0];
NSLog (@"quantity: %@", [item objectForKey: @"quantity"]);
Run Code Online (Sandbox Code Playgroud)
如何汇总阵列所有字典中包含的所有数量?
iphone ×8
objective-c ×6
ios ×2
mfmailcomposeviewcontroller ×2
xcode ×2
cocoa-touch ×1
database ×1
email ×1
ios4 ×1
nsarray ×1
sqlite ×1
uiimage ×1
uiimageview ×1
uikit ×1
uiwebview ×1