【问题标题】:Save image into library directly from APNS直接从 APNS 将图像保存到库中
【发布时间】:2013-11-18 10:21:20
【问题描述】:

我想将图像保存到 iphone sdk 的照片库中。我的图片来自一个网址,而该网址来自 APNS。基本上,当用户单击作为推送通知出现的 URL 时,我想直接将图像保存到 iphone lib 中而不打开应用程序。现在我正在这样做,但我不想显示我只想保存的图像。

-(void) sshowansimage:(NSString *) strImageURL
{

     NSURL *imageURL = [NSURL URLWithString:strImageURL];
     NSLog(@"coming URL is %@", strImageURL);
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
          NSData *imageData = [NSData dataWithContentsOfFile:strImageURL];
          [self performSelectorOnMainThread:@selector(showImage:) withObject:imageData waitUntilDone:YES];
     });

}

-(void)showImage:(NSData*)imageAsData
{
     NSLog(@"IN image view mthhod data is %d",imageAsData.length);
     ansinage.image = [UIImage imageWithData:imageAsData];

}

【问题讨论】:

    标签: ios apple-push-notifications apns-php


    【解决方案1】:

    您可以将您的图像用作 NSData 并将其存储到相册中。首先您需要将您的 NSData 转换为图像对象,然后执行以下操作。

    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    

    【讨论】:

      【解决方案2】:

      使用以下代码将图像直接存储到相册

       UIImage *image=[UIImage imageWithData: imageData];
      UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
      

      【讨论】:

      • 如何打开库是什么意思?是否要打开 UIImagePicker 控制器
      • 好的,然后只需在 appDelegate 中添加图像选择器方法并通过创建 appdelegete 对象在视图控制器中调用它
      猜你喜欢
      • 2017-12-13
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多