Latest 1.0.1
Homepage https://github.com/whf5566/TPWidgetBridge
License MIT
Platforms ios 8.0, requires ARC
Authors

License MIT 
Carthage compatible 
CocoaPods 
CocoaPods 
Support 
Build Status

TPWidgetBridge是一个简单的工具,能让App container 和 widget 更方便的通信。TPWidgetBridge使用了 CFNotificationCenter Darwin 通知,能实时地在App container 和 widget之间传递消息。

安装使用

开发环境

  • xcode8及以上
  • ios7及以上

使用CocoaPods安装

  • 添加「 pod ‘TPWidgetBridge’ 」到你的Podfile文件中,然后在命令行中运行 pod install

使用Carthage安装

  • 添加「 git "https://github.com/whf5566/TPWidgetBridge.git" "master" 」到你的Cartfile文件中,然后在命令行中运行 carthage update –platform iOS
  • 在你的项目中添加刚才生成的TPWidgetBridge.framework动态库

源码引入

  • 将TPWidgetBridge.h TPWidgetBridge.m文件拖入到你的项目中即可

Demo

// 发送通知
__weak typeof(self) weakSelf = self;
[self.widgetBridge postNotificationName:kWidgetNotifyNewText message:text timeout:0.5f response:^(TPWidgetBridgeResponseResult result, id<NSCoding> message) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        if (result == TPWidgetBridgeResponseSuccess) {
            [strongSelf showResponseMessage:message];
        } else if (result == TPWidgetBridgeResponseTimeOut) {
            [strongSelf showResponseMessage:@"Timeout: App did not respond"];
        }
    }];

// 接收通知
__weak typeof(self) weakSelf = self;
[self.widgetBridge observeNotificationName:kWidgetNotifyNewText
                                  observer:^(id<NSCoding> message, TPWidgetBridgeCallBackBlock callback) {
                                          __strong typeof(weakSelf) strongSelf = weakSelf;
                                          strongSelf.textLabel.text = message;
                                          callback(@"did received");
                                }];

Blog

Wellphone

Latest podspec

{
    "name": "TPWidgetBridge",
    "version": "1.0.1",
    "homepage": "https://github.com/whf5566/TPWidgetBridge",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "whf5566": "[email protected]"
    },
    "social_media_url": "https://www.wellphone.me",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/whf5566/TPWidgetBridge.git",
        "tag": "v1.0.1"
    },
    "source_files": "TPWidgetBridge/TPWidgetBridge",
    "public_header_files": "TPWidgetBridge/TPWidgetBridge/*.{h}",
    "requires_arc": true,
    "summary": "TPWidgetBridge creates a bridge between an iOS extension and its containing application.",
    "description": "# TPWidgetBridgenTPWidgetBridge creates a bridge between an iOS extension and its containing application.The TPWidgetBridge supports CFNotificationCenter Darwin Notifications in an effort to support realtime change notifications."
}

Pin It on Pinterest

Share This