Code Monkey home page Code Monkey logo

beacon-passbook-ios's Introduction

Beacon-Passbook-iOS

显示如何添加一个使用iBeacon的Passbook,并在界面上显示此Passbook。

Passbook生成

与普通的Passbook生成相似,Passbook生成相关内容参照Passbook Programming Guide

在生成Passbook用的pass.json文件中,加入下面的Beacon相关项。

"beacons" : [
  {
    "major" : 8,
    "minor" : 8,
    "proximityUUID" : "E2C56DB5-DFFB-48D2-B060-D0F5A71096E0",
    "relevantText" : "this is beacon tests,it must be successfull!!"
  }
  ],

一个Passbook可以与多个beacon相关联。Major和Minor项可以忽略,在忽略时,只要没有忽略的项匹配即可显示相应的Passbook。

##Passbook添加

使用PassKit进行添加。下面为OC代码

    NSURL * passPath = [[NSBundle mainBundle] URLForResource:@"Generic" withExtension:@"pkpass"];
    
    NSError * error = nil;
    NSData * passData = [NSData dataWithContentsOfURL:passPath options:0 error:&error];
    
    PKPass* pkPass = [[PKPass alloc] initWithData:passData error:&error];
    PKPassLibrary * passLibrary = [[PKPassLibrary alloc] init];
    
    BOOL contained = [passLibrary containsPass:pkPass];
    
    if (contained == NO) {
        PKAddPassesViewController *vc = [[PKAddPassesViewController alloc] initWithPass:pkPass];
        if (vc) {
            [vc setDelegate:self];
            [self presentViewController:vc animated:YES completion:nil];
        }
    }else{
        [[UIApplication sharedApplication] openURL:[pkPass passURL]];
    }

##实验

  1. 在App中点击添加,把相应的Passbook添加到系统中,是否添加成功可以通过自带的Passbook App来查看。
  2. 配置云子,在其他手机打开配置工具,或者把App中的二维码保存到相册中。找到需要配置的云子,在云子配置页面,使用“扫一扫配置”读取二维码,然后点击保存,云子配置成功。
  3. 在配置好的云子附近,关闭屏幕,然后使用开关键电量屏幕,此时屏幕中会显示刚刚添加的Passbook的尖端提示。
  4. 在提示上划过后,在不解锁屏幕的情况下,可以显示Passbook,方便用户使用。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.