質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

import

自身のプラットフォーム・プログラム・データセットに対して、外部ソースを取り込むプロセスをimportと呼びます。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

Q&A

解決済

1回答

930閲覧

SpotifyのAPIを使いたくてimportしたはずのheaderがnot foundになる

退会済みユーザー

退会済みユーザー

総合スコア0

Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

import

自身のプラットフォーム・プログラム・データセットに対して、外部ソースを取り込むプロセスをimportと呼びます。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

0グッド

1クリップ

投稿2017/10/05 07:16

編集2017/10/05 07:23

###前提・実現したいこと
Swift4とxcode9.0でSpotifyのAPIを使ってみるアプリ("SpotifyStudy")を開発しています。

このアプリが起動するとSpotifyのログイン画面が立ち上がり、自分のアカウントでログインすると楽曲が再生されるという仕組みです。

Spotifyの公式チュートリアルがObjective-C用だったのでSwiftで使うためにBridge Headerを自分なりに調べて書いていたのですが以下のような2つのエラーが解決できません。

###発生している問題・エラーメッセージ

/Users/[私のユーザネーム]/Desktop/SpotifyStudy/SpotifyStudy/SpotifyStudy/SpotifyStudy-Bridging-Header.h:13:9: error: 'SpotifyAuthentication/SpotifyAuthentication.h' file not found #import <SpotifyAuthentication/SpotifyAuthentication.h>
<unknown>:0: error: failed to emit precompiled header '/Users/[私のユーザネーム]/Library/Developer/Xcode/DerivedData/SpotifyStudy-aasqdpuzvhmgwneqbieddvtsoiam/Build/Intermediates.noindex/PrecompiledHeaders/SpotifyStudy-Bridging-Header-swift_RTWEOMNR105G-clang_149BTWH3ZJQG5.pch' for bridging header '/Users/[私のユーザネーム]/Desktop/SpotifyStudy/SpotifyStudy/SpotifyStudy/SpotifyStudy-Bridging-Header.h'

###該当のソースコード

Swift

1// 2// AppDelegate.swift 3// SpotifyStudy 4// 5// Created by [私のユーザネーム] on 2017/10/04. 6// Copyright © 2017年 [私のユーザネーム]. All rights reserved. 7// 8 9import UIKit 10 11@UIApplicationMain 12class AppDelegate: UIResponder, UIApplicationDelegate, SPTAudioStreamingDelegate { 13 14 var window: UIWindow? 15 16 let kClientId = "[私のClient ID]" 17 let kRedirectUri = NSURL(string: "[私のRedirect URI]") 18 19 var session: SPTSession? 20 var player: SPTAudioStreamingController? 21 22 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 23 // Override point for customization after application launch. 24 25 // set up Spotify 26 SPTAuth.defaultInstance().clientID = kClientId 27 SPTAuth.defaultInstance().redirectURL = kRedirectUri 28 SPTAuth.defaultInstance().requestedScopes = [SPTAuthStreamingScope] as [AnyObject] 29 let loginUrl = SPTAuth.defaultInstance().loginURL 30 application.openURL(loginUrl) 31 32 return true 33 } 34 35 // handle auth 36 func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool{ 37 38 if SPTAuth.defaultInstance().canHandleURL(url){ 39 40 SPTAuth.defaultInstance().handleAuthCallbackWithTriggeredAuthURL(url, callback: { error, session in 41 42 if error != nil{ 43 print("*** Auth error: (error)") 44 } 45 46 // Call the -loginUsingSession: method to login SDK 47 self.loginUsingSession(session) 48 }) 49 50 return true 51 } 52 53 return false 54 } 55 56 func loginUsingSession(session: SPTSession){ 57 58 // Get the player Instance 59 player = SPTAudioStreamingController.sharedInstance() 60 61 if let player = player { 62 63 player.delegate = self 64 65 // Start the player (will start a thread) 66 try! player.startWithClientId(kClientId) 67 68 // Login SDK before we can start playback 69 player.loginWithAccessToken(session.accessToken) 70 } 71 } 72 73 // MARK: SPRAudioStreamingDelegate. 74 75 func audioStreamingDidLogin(audioStreaming: SPTAudioStreamingController!){ 76 77 let urlStr = "spotify:track:6ZSvhLZRJredt15aJiBQqv" // track available in Japan 78 player!.playSpotifyURL(urlStr, startingWithIndex: 0, startingWithPosition: 0, callback: { error in 79 80 if error != nil { 81 82 print("*** failed to play: (error)") 83 return 84 } else { 85 print("play") 86 } 87 }) 88 89 } 90 91 func applicationWillResignActive(_ application: UIApplication) { 92 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 93 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 94 95 } 96 97 func applicationDidEnterBackground(_ application: UIApplication) { 98 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 99 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 100 } 101 102 func applicationWillEnterForeground(_ application: UIApplication) { 103 // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 104 } 105 106 func applicationDidBecomeActive(_ application: UIApplication) { 107 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 108 } 109 110 func applicationWillTerminate(_ application: UIApplication) { 111 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 112 } 113 114 115} 116

Objective

1// 2// AppDelegate.h 3// SpotifyStudy 4// 5// Created by [私のユーザネーム] on 2017/10/04. 6// Copyright © 2017年 [私のユーザネーム]. All rights reserved. 7// 8 9#ifndef AppDelegate_h 10#define AppDelegate_h 11 12#import <SpotifyAuthentication/SpotifyAuthentication.h> 13#import <SpotifyAudioPlayback/SpotifyAudioPlayback.h> 14#import <SafariServices/SafariServices.h> 15#import <SpotifyStudy-Bridging-Header.h> 16 17#endif /* AppDelegate_h */

###試したこと
以下のサイトのことは全て試しました。
http://www.hawk-a.com/exception_code/archives/906
https://qiita.com/titoi2/items/abe7b58a9e644b29e8c3
https://qiita.com/mokemokechicken/items/6716193cfcbd0a4d8b84

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

①Bridging-Header.hファイルにframeworkフォルダ名ではなく個別のヘッダファイル名を直接記述した。
(修正前)
#import <SpotifyAudioPlayback/SpotifyAudioPlayback.h>

(修正後)
#import <SpotifyAuthentication/SPTAuth.h>
#import <SpotifyAuthentication/SPTSession.h>

②AppDelegate.swiftファイルに#import AVKitの一文を記述。
(修正前)
import UIKit

(修正後)
import UIKit
import AVKit

───────────────────────────
"Use of undeclared type 'xxx'"のエラーについては
Build Settings > Objective C Bridging HeaderのHeaderパスを一回削除してもう一度記入し直すのも有効だった。

投稿2017/10/10 08:44

編集2017/10/17 10:01
退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問