Skip to content

Commit

Permalink
add web view
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis committed Jan 8, 2014
1 parent 574fa6f commit 25a3551
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 12 deletions.
12 changes: 9 additions & 3 deletions VZ.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
1F043A16187C18CC00EFA890 /* VZWebViewC.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F043A15187C18CC00EFA890 /* VZWebViewC.m */; };
1F0F989118385C2E000CE764 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1F0F989018385C2E000CE764 /* [email protected] */; };
1F0F989418388E0E000CE764 /* VZCommentCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F0F989318388E0E000CE764 /* VZCommentCell.m */; };
1F0F98971838987C000CE764 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1F0F98951838987C000CE764 /* [email protected] */; };
Expand Down Expand Up @@ -62,6 +63,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
1F043A14187C18CC00EFA890 /* VZWebViewC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VZWebViewC.h; sourceTree = "<group>"; };
1F043A15187C18CC00EFA890 /* VZWebViewC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VZWebViewC.m; sourceTree = "<group>"; };
1F0F989018385C2E000CE764 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
1F0F989218388E0E000CE764 /* VZCommentCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VZCommentCell.h; sourceTree = "<group>"; };
1F0F989318388E0E000CE764 /* VZCommentCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VZCommentCell.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -259,6 +262,8 @@
1FDF3B20185445450069834B /* VZPostActionC.m */,
1F80240F18797A80005F4005 /* VZStatusListC.h */,
1F80241018797A80005F4005 /* VZStatusListC.m */,
1F043A14187C18CC00EFA890 /* VZWebViewC.h */,
1F043A15187C18CC00EFA890 /* VZWebViewC.m */,
);
name = C;
sourceTree = "<group>";
Expand Down Expand Up @@ -430,6 +435,7 @@
1F0F989418388E0E000CE764 /* VZCommentCell.m in Sources */,
1FF2A341183B0D3500731771 /* VZSettingsC.m in Sources */,
1FDD7527181BA4B400F490A3 /* VZPost.m in Sources */,
1F043A16187C18CC00EFA890 /* VZWebViewC.m in Sources */,
1FDD752A181BAE0600F490A3 /* VZPostCell.m in Sources */,
1F4C5C121849B6ED00AB3696 /* VZNavC.m in Sources */,
1F664F8B182375A500DA43F1 /* VZPostViewC.m in Sources */,
Expand Down Expand Up @@ -536,7 +542,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 8B4AF051FD3B4904A6F9F111 /* Pods-VZ.xcconfig */;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "";
Expand All @@ -550,7 +556,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "39BACF4F-15FE-4870-AFA4-326464A0FEFF";
VALID_ARCHS = "armv7 armv7s";
VALID_ARCHS = "armv7 armv7s arm64";
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -559,7 +565,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 8B4AF051FD3B4904A6F9F111 /* Pods-VZ.xcconfig */;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "";
Expand Down
2 changes: 1 addition & 1 deletion VZ/VZMenuC.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *
case 2:
{
UIViewController *vc= [self.storyboard instantiateViewControllerWithIdentifier:@"NearC"];
[nav setViewControllers:@[vc] animated:NO];
[nav setViewControllers:@[vc] animated:YES];
}

case 3:
Expand Down
72 changes: 64 additions & 8 deletions VZ/VZStatusListC.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "VZStatusListC.h"
#import "VZM.h"
#import "VZNavView.h"

#import "VZWebViewC.h"
#import <AVOSCloud/AVStatus.h>

@interface VZStatusListC (){
Expand All @@ -36,11 +36,15 @@ - (void)viewDidLoad
[super viewDidLoad];
self.tableView.backgroundColor=[UIColor clearColor];
self.tableView.backgroundView=[[UIImageView alloc] initWithImage:[VZTheme bgImage]];

self.navigationItem.titleView=self.refreshView=[VZProgressView new];

UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTitleTap:)];
[self.navigationItem.titleView addGestureRecognizer:tap];

[self showRefresh];
[self loadNew];


}
-(void)onTitleTap:(UITapGestureRecognizer*)tap{
Expand All @@ -66,7 +70,7 @@ -(void)showRefresh{

updateRefreshView=YES;
[UIView animateWithDuration:0.2 animations:^{
[self.tableView setContentInset:UIEdgeInsetsMake([VZNavView height]+REFRESH_TRIGGER, 0, 0, 0)];
[self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}];

self.refreshView.infinite=YES;
Expand Down Expand Up @@ -100,7 +104,28 @@ -(void)scrollViewDidScroll:(UIScrollView *)scrollView{

-(void)loadNew{
__weak typeof(self) ws=self;
[AVStatus getInboxStatuses:^(NSArray *objects, NSError *error) {
[AVStatus getStatusesWithType:kAVStatusTypeTimeline skip:0 limit:100 andCallback:^(NSArray *objects, NSError *error) {

AVStatus *status=[[AVStatus alloc] init];
[status setData:@{
@"text":@"hello link",
@"content":@"http://baidu.com",
}];

AVStatus *status3=[[AVStatus alloc] init];
[status3 setData:@{
@"text":@"hello store",
@"content":@"http://itunes.apple.com/us/app/iq-test-sale/id297141027?mt=8&uo=6",
}];

AVStatus *status2=[[AVStatus alloc] init];
[status2 setData:@{
@"text":@"hello post",
@"content":@"post://52342342343",
}];

objects=@[status,status2,status3];

ws.statuses=objects;
[ws.tableView reloadData];
[ws hideRefreshView];
Expand All @@ -111,25 +136,56 @@ -(void)loadNew{

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.statuses.count;
return 1;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
return self.statuses.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
static NSString *CellIdentifier = @"StatusCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

AVStatus *status=[self.statuses objectAtIndex:indexPath.row];
NSDictionary *data=status.data;

cell.textLabel.text=data[@"text"];

return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

AVStatus *status=[self.statuses objectAtIndex:indexPath.row];
NSDictionary *data=status.data;
NSString *content= data[@"content"];

NSArray *cpt=[content componentsSeparatedByString:@"://"];

NSString *scheme=cpt[0];

if ([scheme hasPrefix:@"post"]) {
VZPost *post=[VZPost objectWithoutDataWithObjectId:cpt[1]];
[post fetchIfNeededInBackgroundWithBlock:^(AVObject *object, NSError *error) {

}];
}else if([scheme hasPrefix:@"http"]){
VZWebViewC *webc=[[VZWebViewC alloc] init];

[webc loadURL:content];

[self.navigationController pushViewController:webc animated:YES];
}
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down
16 changes: 16 additions & 0 deletions VZ/VZWebViewC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// VZWebViewC.h
// VZ
//
// Created by Travis on 14-1-7.
// Copyright (c) 2014年 Plumn LLC. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface VZWebViewC : UIViewController<UIWebViewDelegate>
@property(nonatomic,strong) UIWebView *webView;

-(void)loadURL:(NSString*)url;

@end
129 changes: 129 additions & 0 deletions VZ/VZWebViewC.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//
// VZWebViewC.m
// VZ
//
// Created by Travis on 14-1-7.
// Copyright (c) 2014年 Plumn LLC. All rights reserved.
//

#import "VZWebViewC.h"
#import "VZProgressView.h"
#import <StoreKit/SKStoreProductViewController.h>

#import <SIAlertView/SIAlertView.h>

@interface VZWebViewC ()<SKStoreProductViewControllerDelegate>
@property(nonatomic,strong) VZProgressView *refreshView;
@end

@implementation VZWebViewC


- (id)init
{
self = [super init];
if (self) {
self.webView=[[UIWebView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.webView];

self.webView.delegate=self;

self.webView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];


self.navigationItem.titleView=self.refreshView=[VZProgressView new];
self.refreshView.progress=1;

}


-(void)loadURL:(NSString*)url{
NSURLRequest *req=[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[self.webView loadRequest:req];
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSURL *url=request.URL;
if ([url.host hasPrefix:@"itunes.apple.com"]) {
NSRegularExpression *re=[NSRegularExpression regularExpressionWithPattern:@"id([0-9]{8,})" options:0 error:nil];
NSTextCheckingResult *result= [re firstMatchInString:url.path options:NSMatchingReportCompletion range:NSMakeRange(0, url.path.length)];

if (result) {
NSString *storeId=[url.path substringWithRange:[result rangeAtIndex:1]];
if (storeId) {
__weak typeof(self) ws=self;

SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init];
// Configure View Controller
[storeProductViewController setDelegate:(id)self];
[storeProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier : storeId}

completionBlock:^(BOOL result, NSError *error) {
if (error) {
NSLog(@"Error %@ with User Info %@.", error, [error userInfo]);

SIAlertView *alertView = [[SIAlertView alloc] initWithTitle:@"出错了" andMessage:[error localizedDescription]];

[alertView addButtonWithTitle:@"确定"
type:SIAlertViewButtonTypeCancel
handler:^(SIAlertView *alert) {

}];

alertView.transitionStyle = SIAlertViewTransitionStyleDropDown;

[alertView show];

} else {
// Present Store Product View Controller
[self presentViewController:storeProductViewController animated:YES completion:nil];
}

ws.refreshView.infinite=NO;
}];

self.refreshView.infinite=YES;
return NO;
}
}

}

return YES;
}

-(void)webViewDidStartLoad:(UIWebView *)webView{
self.refreshView.infinite=YES;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
self.refreshView.infinite=NO;
}

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
self.refreshView.infinite=NO;

SIAlertView *alertView = [[SIAlertView alloc] initWithTitle:@"出错了" andMessage:[error localizedDescription]];

[alertView addButtonWithTitle:@"确定"
type:SIAlertViewButtonTypeCancel
handler:^(SIAlertView *alert) {

}];

alertView.transitionStyle = SIAlertViewTransitionStyleDropDown;

[alertView show];
}

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end

0 comments on commit 25a3551

Please sign in to comment.