2015-09-25 3 views
6

私は現在、watchOS 2アプリケーションの複雑さを設定しています。watchOSの複雑さに画像を表示するには

私は合併症の3つの異なる種類を提供したい:

  • 功利小さな
  • モジュラーsmallist項目
  • 単に私のアプリのアイコンを表示する必要がある円形の小さな

すべてのこれらの合併症の種類画像。私ClockKitクラスでは、私は次のメソッド実装されています:

func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimelineEntry?) -> Void) { 

    if complication.family == .CircularSmall { 

     let template = CLKComplicationTemplateCircularSmallRingImage() 
     template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "app_icon")!) 
     let timelineEntry = CLKComplicationTimelineEntry(date: NSDate(), complicationTemplate: template) 
     handler(timelineEntry) 

    } else if complication.family == .UtilitarianSmall{ 

     let template = CLKComplicationTemplateUtilitarianSmallRingImage() 
     template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "app_icon")!) 
     let timelineEntry = CLKComplicationTimelineEntry(date: NSDate(), complicationTemplate: template) 
     handler(timelineEntry) 

    } else if complication.family == .ModularSmall { 

     let template = CLKComplicationTemplateModularSmallRingImage() 
     template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "app_icon")!) 
     let timelineEntry = CLKComplicationTimelineEntry(date: NSDate(), complicationTemplate: template) 
     handler(timelineEntry) 

    } else { 

     handler(nil) 

    } 

} 

を私は私のアイデアを実現する適切な方法だか分からないので、私はちょうど私の合併症として画像を表示するためのコードを知りたいのですが。誰も私がこれをどのように達成できるかを知っていますか?

答えて

10

最初に、まだ見ていない限り、合併症についてApple's sessionを見ることを強くお勧めします。

あなたは、少なくともあなたのComplicationControllerCLKComplicationDataSourceの3次非オプションのメソッドを実装する必要があります。

public func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) 
public func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimelineEntry?) -> Void) 
public func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) 

他のすべてのメソッドはオプションです。あなたが見る限り、あなたは2番目のものだけを実装しました。 2は、あなたのコンテキストで、次のことができ、残りの実装:

class ComplicationController: NSObject, CLKComplicationDataSource { 

    func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) { 
     // Turn off time travelling 
     handler([CLKComplicationTimeTravelDirections.None]) 
    } 

    func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) { 
     var template: CLKComplicationTemplate? 

     switch complication.family { 
      case .CircularSmall: 
       template = CLKComplicationTemplateCircularSmallRingImage() 
       template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "app_icon")!) 
      case .UtilitarianSmall: 
       template = CLKComplicationTemplateUtilitarianSmallRingImage() 
       template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "app_icon")!) 
      case .ModularSmall: 
       template = CLKComplicationTemplateModularSmallRingImage() 
       template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "app_icon")!) 
      case .ModularLarge: 
       template = nil 
      case .UtilitarianLarge: 
       template = nil 
     } 

     handler(template) 
    } 

} 

そして$(PRODUCT_MODULE_NAME).ComplicationControllerとして、合併症の設定であなたのデータソースクラスを指定し、適切なチェックボックスをチェックすることを忘れないでください。 enter image description here

これは、あなたの場合の最小の複雑な設定です。

+0

詳細な回答ありがとうございます。おそらく私はすでにこれらのメソッドを実装していることを明確にしていませんでした。それ以外の場合はアプリケーションを構築できませんでした。あなたが提案したWWDCセッションビデオを見ていきます。 – fredpi

+0

@ pi1000 - 設定スクリーンショットで答えを更新しました。私が付けた設定を含め、あなたがやったすべてのことを列挙する必要があると思います。 –

+0

ええ、ありがとう、しかしまだいくつかの誤解。私は、複雑な丸形の円を見ていますが、私はそのようなテンプレートを持っていないと私はイメージとして私のアプリのアイコンを使用できるかどうかを知りたいです。 – fredpi

関連する問題