SUAI
SUAI 是一个轻量级且非常简单的库,用于处理圣彼得堡国家航空航天仪器大学的内容。使用这个库,您可以
- 获取从排课网站引用的班级、教师和教室的日程。
- 获取大学新闻。
此库用于官方SUAI应用程序 "スペースナビ ГУАП"。
示例
要运行示例项目,克隆仓库,然后首先从Example目录运行 pod install
。
安装
SUAI 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的Podfile即可
pod 'SUAI'
使用方法
时间表
如果你知道实体名称及其类型,请使用
- (void)loadScheduleFor:(NSString *)entityName
ofType:(Entity)type
success:(void (^) (SUAISchedule *schedule))schedule
fail:(void (^) (__kindof SUAIError *error))error;
或者如果你有实体上的SUAIEntity对象,请使用
- (void)loadScheduleFor:(SUAIEntity *)entity
success:(void (^) (SUAISchedule *schedule))schedule
fail:(void (^) (__kindof SUAIError *error))error;
以上方法类似,如果在没有错误的情况下获得了时间表,则将调用成功块。在所有情况下,失败块是您的服务:)。如何加载类型为“1741”的群组的时间表的示例:
Objective-C
[[[SUAI instance] schedule] loadScheduleFor:@"1741" ofType:EntityTypeGroup success:^(SUAISchedule *schedule) {
NSLog(@"OK: %@", schedule);
} fail:^(__kindof SUAIError *error) {
NSLog(@"error: %@", error.description)
}];
Swift
SUAI.instance().schedule.loadSchedule(for: "1741", of: .group, success: { (schedule) in
print("OK: \(schedule)")
}) { (error) in
print("error: \(error.description)")
}
新闻
要加载可用新闻预览,请使用此方法
- (void)loadAllNews:(void (^) (NSArray<SUAINews *>* news))success
fail:(void (^) (SUAIError *err))error;
如果你想要加载具体的新闻,请使用
- (void)loadNews:(NSString *)newsID
success:(void (^) (SUAINews *news))success
fail:(void (^) (SUAIError *err))error;
其中newsID是存储在SUAINews对象属性的publicationId中的URL的一部分。
通知
库也包含通知常量。如果您需要对其变化做出响应,请订阅它
- kSUAIReachabilityNotification:如果您订阅了这个通知常量,您将能够处理网络可达性的更改(例如,设备离线或通过Wi-fi或LTE连接)。在通知对象中,您将获得包含布尔值可达状态 NSNumber。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(p_internetReachabilityChanged:)
name:kSUAIReachabilityNotification object:nil];
在方法 p_internetReachabilityChanged 中,您可以检查可达状态
- (void)p_internetReachabilityChanged:(NSNotification *)notification {
BOOL isReachable = [(NSNumber *)[notification object] boolValue];
NSLog(@"internet is reachable: %ld", isReachable);
}
- kSUAIWeekTypeObtainedNotification:常量将在 SUAI 加载当前周的类型时通知。
- kSUAIEntityLoadedNotification:在您能够加载时间表之前,必须加载所有可用的代码。这个常量会在所有代码都加载并准备好使用时通知。
重要
不要忘记允许任意加载!
- 转到plist文件;
- 在信息属性列表中添加新键“App Transport Security Settings”;
- 在添加的字典中添加键“Allow Arbitrary Loads”并将值设置为YES。
需求
- Xcode
- Objective-C
- iOS 9.0或更高版本
作者
Victor Volkov, [email protected]
许可
SUAI可在MIT许可下获得。有关更多信息,请参阅LICENSE文件。