BrightCenterSDK 1.3.2

BrightCenterSDK 1.3.2

测试已测试
语言语言 Obj-CObjective C
许可证 Apache 2
发布最后发布2014年12月

未知 维护。



 
依赖关系
AFNetworking~> 1.3.2
MBProgressHUD~> 0.7
 

  • 作者
  • Tom van Zummeren

Brightcenter SDK

使用此 SDK,可以轻松与 Brightcenter 后端进行通信。它还包含学生选择器,可以帮助您登录到 Brightcenter 并从一组学生中选择。

要求

  • 仅适用于 iPad(目前如此)
  • iOS 5, iOS 6 或 iOS 7

将此 SDK 集成到您的教学应用中

前往您的 XCode 项目目录,创建一个名为 PodFile 的文本文件,内容如下

platform :ios, '5.0'
pod 'BrightCenterSDK', '~> 1.2'

现在在终端中打开您的 XCode 项目目录,并运行 pod install 命令。就这样!使用 XCode 或 AppCode 打开生成的 YourApp.xcworkspace 文件(而不是 YourApp.xcodeproj)。

配置环境

在您的 AppDelegate 中添加此行以使用 Brightcenter 生产环境

[[BCStudentsRepository instance] configureForSandbox];

使用 Brightcenter 登录按钮

我们创建了一个漂亮的按钮,您可以在代码中实现它,这样就无需自己实现 studentPicker。将以下代码添加到您想添加按钮的 viewcontroller 中

- (void) addOverlayButtonWithColor: (int) color andPosition: (int) position{
    UIColor *logoColor;
    switch (color) {
        case 1:
            logoColor =[UIColor colorWithRed:244 / 255.0 green:126 / 255.0 blue:43 / 255.0 alpha:1.0];
            break;
        case 2:
            //blue
            logoColor = [UIColor colorWithRed:0 / 255.0 green:156 / 255.0 blue:250 / 255.0 alpha:1.0];
            break;
        case 3:
            //grey
            logoColor = [UIColor colorWithRed:77 / 255.0 green:77 / 255.0 blue:77 / 255.0 alpha:1.0];
            break;
        default:
            logoColor = [UIColor colorWithRed:244 / 255.0 green:126 / 255.0 blue:43 / 255.0 alpha:1.0];
            break;
    }

    CGSize size = self.view.frame.size;
    CGFloat logoSize = MIN(size.width / 3, size.height / 3) * 0.5;

    int x = 0;
    int y = 0;

    double margin = 0.8;
    int posX = 0;
    int posY = 0;
    int trans = logoSize / 3;
    switch (position) {
        case 1:
            x = (logoSize * margin) - logoSize;
            y = (logoSize * margin) - logoSize;
            posX = 4;
            posY = 4;
            break;
        case 2:
            x = size.width - (logoSize * margin);
            y = (logoSize * margin) - logoSize;
            posX = trans;
            posY = 4;
            break;
        case 3:
            x = (logoSize * margin) - logoSize;
            y = size.height - (logoSize * margin);
            posX= 0;
            posY = trans;
            break;
        case 4:
            x = size.width - (logoSize * margin);
            y = size.height - (logoSize * margin);
            posX = trans;
            posY = trans;
            break;

        default:
            x = size.width - (logoSize * margin);
            y = size.height - (logoSize * margin);
            break;
    }
    BCButtonLogo *backgroundView;
    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
        backgroundView = [[BCButtonLogo alloc] initWithColor:logoColor andPositionX:posX andPositionY:posY];
        [self.view addSubview:backgroundView];

        backgroundView.frame = CGRectMake(x, y, logoSize, logoSize);
    } else if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
        backgroundView = [[BCButtonLogo alloc] initWithColor:logoColor andPositionX:posY andPositionY:posX];
        [self.view addSubview:backgroundView];

        backgroundView.frame = CGRectMake(y, x, logoSize, logoSize);
    }
    backgroundView.bcButtonClickedDelegate = self;
}

- (void) bcButtonIsClicked{
    BCStudentPickerController *studentPickerController = [BCStudentPickerController new];
    studentPickerController.studentPickerDelegate = self;
    if (studentPickerController) {
        [self presentViewController:studentPickerController animated:YES completion:nil];
    }
}

您还需要将您的 viewcontroller 设置为 BCStudentPickerControllerDelegateBCButtonLogoClickedDelegate 的代理。您可以按以下方式完成此操作

@interface MyCoolEduAppController : UIViewController <BCStudentPickerControllerDelegate, BCButtonLogoClickedDelegate>

在您的代码中,您可以通过调用 addOverlayButtonWithColor: (int) color andPosition: (int) position 来显示按钮。颜色编号代表以下:1 为橙色,2 为蓝色,3 为灰色。位置如下:1 为左上角,2 为右上角,3 为左下角,4 为右下角。

该协议还要求您实现一个简单的方法

- (void) studentPicked:(BCStudent *) student {
    // Save the student object for later. It is needed later to register assessment item results for this student.
    // Also you can use it right now to display the name of this student somewhere in your app.
}

在上面的方法被调用后,学生选择器会自动关闭,您可以让选择的学生完成您想要的练习。

从您的应用中手动登录到 Brightcenter

SDK 包含一些界面,可以直接登录到 Brightcenter 并从一组学生中选择,无需额外配置。要打开登录界面/学生选择器,将 BCStudentPickerController 作为模态视图控制器呈现

BCStudentPickerController *studentPickerController = [BCStudentPickerController new];
studentPickerController.studentPickerDelegate = self;
[self presentViewController:studentPickerController animated:YES completion:nil];

如你所见,它将控制器(self)赋值给了代理。为此,您必须按照以下方式遵循 BCStudentPickerControllerDelegate 协议

@interface MyCoolEduAppController : UIViewController <BCStudentPickerControllerDelegate>

可选地,您可以实现注销方法

- (void) loggedOut{
    //Use this to log out in your app if necessary
}

学生完成练习后(在Brightcenter中称为评估项目),您需要通知Brightcenter。

直接使用API(无需UI)

通过使用BCStudentsRepository,您可以直接访问Brightcenter API。您可以始终这样获取BCStudentsRepository的共享(单例)实例

BCStudentsRepository *repository = [BCStudentsRepository instance];

注册新的评估项目结果

这就是注册评估项目结果的方式

BCStudentsRepository *repository = [BCStudentsRepository instance];
BCAssessmentItemResult *result = [BCAssessmentItemResult new];
result.student = self.student;
result.questionId = @"123";
result.assessment = [BCAssessment assessmentWithId:@"456"];
result.duration = 5;
result.completionStatus = BCCompletionStatusCompleted;
result.score = 10;

// Saving an assessment makes a call to the backend, so it could take a second. It is wise to display an activity indicator.
[repository saveAssessmentItemResult:result success:^{
    // Saving the assessment item was successful!
    // At this point you can hide the progress indicator.
} failure:^(NSError *error, BOOL loginFailure) {
    // Saving the result failed. This could happen when: 
    // 1) the given credentials are no longer valid (loginFailure = YES)
    // 2) or there was a network error 
}];

加载给定评估的所有已注册项目结果

如果您之后需要加载在Brightcenter中为给定评估和学生的所有已注册的评估项目结果

    BCStudentsRepository *repository = [BCStudentsRepository instance];

    // Loading the registered results makes a call to the backend, so it could take a second. It is wise to display an activity indicator.
    [repository loadAssessmentItemResults:[BCAssessment assessmentWithId:@"456"]
                                  student:self.student
                                  success:^(NSArray *assessmentItemResults) {
                                      // Given is an NSArray of BCAssessmentItemResults, do with it whatever you like
                                      // At this point you can hide the progress indicator.
                                  }
                                  failure:^(NSError *error, BOOL loginFailure) {
                                      // Saving the result failed. This could happen when:
                                      // 1) the given credentials are no longer valid or
                                      // 2) there was a network error
                                  }];

基本上就这样!如果您有任何问题,请随时联系我。

针对此SDK的开发者

通过运行pod install来获取依赖。

在XCode或AppCode(而不是BrightcenterSDK.xcodeproj)中打开生成的BrightcenterSDK.xcworkspace。

在iPad模拟器或实际的iPad上运行项目。