jeroendesloovere / vcard

This vCard PHP library can easily parse or generate/export vCards as .vcf
https://packagist.org/packages/jeroendesloovere/vcard
MIT License
497 stars 193 forks source link

It's not working with Iphone #140

Open hariom-darkbears opened 5 years ago

hariom-darkbears commented 5 years ago

When i use this on Android, then it's working fine and download a file with .vcf extension.

But when i use this with Iphone then it's not working only show me as output string.(Not downloadable file).

Please quick help!

nettum commented 5 years ago

Are you using $vcard->download() or $vcard->getOutput()? If you are using getOutput() you will need to add the appropriate headers to your response. My guess is that the response are returning something like text/html instead of text/vcard and then iphone will not open it as a contact file.

hariom-darkbears commented 5 years ago

Are you using $vcard->download() or $vcard->getOutput()? If you are using getOutput() you will need to add the appropriate headers to your response. My guess is that the response are returning something like text/html instead of text/vcard and then iphone will not open it as a contact file.

Hey @nettum Yes response are returning like 'text/html'.. could you please help me to write down appropriate headers...

nettum commented 5 years ago

Well, this package already have a function to get the appropriate headers so you could do

foreach ($vcard->getHeaders(false) as $header) {
    header($header);
}

to get all the headers you need and set them. But then you could just use $vcard->download(); instead. In that case you do not need to to set the headers yourself as the library does it for you.

If you still want to do it manually you could use header('Content-Type: text/vcard');

itsmemanoj commented 5 years ago

i'm facing the same download issue on iphone but case is little different. normally if i visit a site and click download button on iphone it works download a contact file. but if click a website link from instagram or facebook app, you know they opens links using in-app browsers. then i click on download button and it shows the string output. but works fine for android.

i did check the function isIOS() it gives TRUE . i do not know what is error. can anyone fix it ?

itsmemanoj commented 5 years ago

@hariom-darkbears did you solve the issue ?

miguelcalderons commented 4 years ago

@itsmemanoj Im using $vcard->download ad still doing it. the weird thing is that only are some users, not all.

Update:

The photo is required? that was my problem.

itsmemanoj commented 4 years ago

@miguelcalderons downloading vCard is working fine for me too but only on known browsers like firefox, safari, chrome. But when I click the download link from the Instagram or facebook Bio ( using their App ). Then you know, they open links using in-app browsers, those browsers are just displaying output string not downloading the file.

kaleemshoukat commented 2 years ago

Best solution for iphone is replace $vcard->download(); with following:

$response = new Response(); $response->setContent($vcard->getOutput()); $response->setStatusCode(200); $response->headers->set('Content-Type', 'text/x-vcard'); $response->headers->set('Content-Disposition', 'attachment; filename="' . $name_here . '.vcf"'); $response->headers->set('Content-Length', mb_strlen($vcard->getOutput(), 'utf-8')); return $response;

ElifBahar commented 2 years ago

Best solution for iphone is replace $vcard->download(); with following:

$response = new Response(); $response->setContent($vcard->getOutput()); $response->setStatusCode(200); $response->headers->set('Content-Type', 'text/x-vcard'); $response->headers->set('Content-Disposition', 'attachment; filename="' . $name_here . '.vcf"'); $response->headers->set('Content-Length', mb_strlen($vcard->getOutput(), 'utf-8')); return $response;

This is working well for me on android phones, however on iOS nothing is happening. Any idea how to fix this? I also tried

$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone"); $response->setContent($content); $response->setStatusCode(200); if( $iPhone ){ $response->headers->set('Content-Type', 'text/vcard'); }else{ $response->headers->set('Content-Type', 'text/x-vcard'); } $response->headers->set('Content-Disposition', 'attachment; filename="'.'contact'.'.vcf"'); $response->headers->set('Content-Length', mb_strlen($content, 'utf-8')); return $response;

but it still does not work on iPhone, nothing happens

aviqa1984 commented 2 years ago

@ElifBahar did you sovled this ??

ElifBahar commented 2 years ago

@aviqa1984 yes but i had to write down the code manually on my controller. I searched online and combined couple of things i found.. Here is how i did it:

`

    public function exportVCF($url){

       //Retrieve the user you want to make a card of
      $user = User::where('url',$url)->first();
      //Create card 
      $content2 = "BEGIN:VCARD\r\n";
      $content2 .= "VERSION:3.0\r\n";
      $content2 .= "CLASS:PUBLIC\r\n";
      $content2 .= "FN:".$user->name."\r\n";
      $content2 .= "N:".$user->name."\r\n";
      if($user->getCompany->count() > 0){
          $company_info = $user->getCompany->first();
          if($company_info->company_name != null){
              $content2 .= "ORG:".$company_info->company_name."\r\n";
          }if($company_info->title != null){
              $content2 .= "TITLE:".$company_info->title."\r\n";
          }if($company_info->work_mail != null){
              $content2 .= "EMAIL;TYPE=internet,pref:".$company_info->work_mail."\r\n";
          }if($company_info->work_phone != null){
              $content2 .= "TEL;TYPE=work,voice:".$company_info->work_phone."\r\n";
          }if($company_info->work_web_site != null){
              $content2 .= "URL:".$company_info->work_web_site."\r\n";
          }if($company_info->address != null){
              $content2 .= "ADR;TYPE=work:".$company_info->address."\r\n";
          }
      }
      $content2 .= "END:VCARD\r\n";

      //Create a response
      $response = new Response();
      $response->setContent($content2);
      $response->setStatusCode(200);
      $response->headers->set('Content-Type', 'text/vcard');
      $response->headers->set('Content-Disposition', 'attachment; filename="'.'contact'.'.vcf"');
      $response->headers->set('Content-Length', mb_strlen($content2, 'utf-8'));

      return $response;
}

`