小编Jan*_*mal的帖子

在检查iphone中的网络可达性后app崩溃了?

我有一个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)

iphone mpmovieplayercontroller avaudiosession

4
推荐指数
1
解决办法
3941
查看次数

将sqlite附加到xcode邮件

我对这段代码感到很疯狂,它应该可以工作,但是当我收到邮件时没有附加文件,这是我的代码:

-(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)

database sqlite email iphone xcode

4
推荐指数
1
解决办法
2847
查看次数

如何更改UIWebview的颜色和字体大小

在我的应用程序中,我正在加载HTML字符串,该字符串是从json文件解析的,字符串已经包含字体颜色和字体大小,但我需要更改字体的颜色和大小.要替换它我已经使用了以下代码,但它不起作用

NSString *webString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'", 
                          textFontSize];
    [web stringByEvaluatingJavaScriptFromString:webString];
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以改变它.如果是的话,请告诉我答案.

iphone uiwebview ios

4
推荐指数
1
解决办法
5179
查看次数

为给定字符串的所有字符突出显示字符串中的特定字符

特殊字符将在标签上用红色突出显示,因此我在下面编写了功能不错的函数,但我想确认一下,还有其他有效的方法吗?例如

-(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

4
推荐指数
1
解决办法
1650
查看次数

将UIImageView转换为UIImage

我正在使用图像,我有很多它们,而且我正在从服务器上实时下载它们,然后才真正快速地使用AsyncImageView类,但是我知道我正在使用自定义类,UIImage而不是UIImageView.

问题:转换UIImageView为有什么好方法UIImage吗?

提前致谢!

xcode objective-c uikit uiimageview uiimage

3
推荐指数
1
解决办法
7582
查看次数

如何通过iphone中的电子邮件发送.caf文件?

我想通过iphone中的电子邮件发送扩展名为.caf的音频文件.任何人都可以帮我这样做吗?我写过,mimeType:@"audio/caf"但我认为不支持.请帮我做这个小任务.

iphone objective-c mfmailcomposeviewcontroller

3
推荐指数
1
解决办法
1450
查看次数

单击文本字段的datepicker

我试图通过单击文本字段来实现日期选择器.我正在使用此链接中提到的代码.

但我没有得到输出.如果有人知道如何通过单击文本字段来提取日期选择器.请给我一些解决方案.

提前致谢.

iphone

2
推荐指数
1
解决办法
2万
查看次数

如何在电子邮件正文中的某些文本后设置第一个图像?

我使用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

2
推荐指数
1
解决办法
2687
查看次数

在iPhone应用程序中按顺序显示图像

我想显示一系列图像,如: 在此输入图像描述

任何人都可以让我知道,有没有API,我可以通过它显示图像,如演示图像所示?

iphone objective-c

2
推荐指数
3
解决办法
653
查看次数

数组中词典的数量总和

我有一个包含NSDictionary列表的NSArray.喜欢:

NSArray *array = ...;
NSDictionary *item = [array objectAtIndex:0];
NSLog (@"quantity: %@", [item objectForKey: @"quantity"]);
Run Code Online (Sandbox Code Playgroud)

如何汇总阵列所有字典中包含的所有数量?

objective-c sum-of-digits nsarray

2
推荐指数
1
解决办法
1254
查看次数