2016-11-06 6 views
0

すぐにサンプルアプリケーションを実行しています。私は自分のアプリから画像を共有する必要があります。 Social frameworkの助けを借りて、FacebookTwitterを統合しました。今、私は私が[のWhatsAppへのWhatsAppにインポートまたはコピー]を選択した場合InstagramWhatsAppiOS:ソーシャルネットワークで画像を共有するSwift

シェアボタンアクション

@IBAction func shareAcn(sender: UITapGestureRecognizer) { 

    var documentController: UIDocumentInteractionController! 

    let fileURL = NSBundle.mainBundle().pathForResource("smc", ofType: "png") 
    documentController = UIDocumentInteractionController.init(URL: NSURL(fileURLWithPath: fileURL!)) 
    documentController.presentOptionsMenuFromRect(CGRectZero, inView: self.view, animated: true) 
} 

と統合する方法のWhatsApp

@IBAction func shareAcn(sender: UITapGestureRecognizer) { 

    var documentController: UIDocumentInteractionController! 
    let image = UIImage(named: "smc") 
    let filename = "myimage.wai" 
    let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, false)[0] as NSString 
    let destinationPath = documentsPath.stringByAppendingString("/" + filename) 
    UIImagePNGRepresentation(image!)!.writeToFile(destinationPath, atomically: false) 
    let fileURL = NSURL(fileURLWithPath: destinationPath) as NSURL 
    documentController = UIDocumentInteractionController.init(URL: fileURL) 
    documentController.UTI = "net.whatsapp.image" 
    documentController.presentOptionsMenuFromRect(CGRectZero, inView: self.view, animated: true) 
} 

を知らないアプリ墜落するWhatsAppを選択した場合、「このアイテムは送信できません」。

Instagramの

var instagramURL: NSURL = NSURL(string: "instagram://user?username=USERNAME") 
if UIApplication.sharedApplication().canOpenURL(instagramURL) { 
    UIApplication.sharedApplication().openURL(instagramURL) 
} 

コードはいずれも作業していません。

私はInstagramをインストールし、私のテストデバイスに私のユーザとしてログオンしています。実行すると、Instagramは開かれません。

私はこれを解決する方法を知らないのですか?親切に私を導く。

+0

参照:http://stackoverflow.com/a/30988328/1457385 – shallowThought

+0

LSApplicationsQueriesSchemes? Info.plistはどこにありますか?私はそれを見つけることができません。 –

+0

if文の中にブレークポイントを置くと、これまでにヒットしますか? – colinrf

答えて

1

info.plistファイルにLSApplicationQueriesSchemesエントリを設定して、どのスキームがクエリを試みるかを宣言していることを確認してください。

<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>whatsapp</string> 
    <string>instagram</string> 
</array> 

「://」は使用しないでください。

「://」を含めると、canOpenUrl:はNOを返します。 canOpenUrlの実際の呼び出しを行うときには、コロンを含める必要があります。つまり、canOpenUrl:@"instagram:"

詳細はthis WWDC 2015 videoにあります。


また、このラインは疑わしいです:

var instagramURL: NSURL = NSURL(string: "instagram://user?username=USERNAME") 

私はあなたがInstagrams documentationからこれをコピーしなかった疑い。その場合は、USERNAMEを実際のユーザー名に置き換えてください。


エラーを特定するには、最初にシンプルなURLをしようとする場合があります:

var instagramURL: NSURL = NSURL(string: "instagram://app") 
関連する問題