ios 技巧总结(不断更新)
2014-12-12 14:07
183 查看
1. 数据格式化输出 1000000 -> 1,000,000
数据格式化输出 1000000 -> 1,000,000
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *numberString = [numberFormatter stringFromNumber:@(1000000)];
_salesCountLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Yesterday you sold %@ apps", nil), numberString];
2.
方式一:跳转打开
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
方式二:应用内打开
通过Modal view方式弹出App Store商品详情页面。我按照文档说明,写了个例子。部分代码如下:
另外,需要实现SKStoreProductViewControllerDelegate如下代理方法:
可以这样调用:
这段代码即实现了上面图示的效果。
注:项目需要添加StoreKit框架,仅在iOS 6.0以上的设备中支持上述实现。
如果需要兼容6.0以下的设备,可以使用下面的代码(这种方式会跳出当前应用):
3.
基本的思路就是,可以为app2定义一个URL,在app1中通过打开这个URL来打开app2,在此过程中,可以传送一些参数。下面来讨论一下具体的实现过程。
2. 在app1的代码中打开刚才定义的URL,代码如下:
当然,这个URL的形式可以是其他形式的,只要以"myapp://"开始即可。
这样,就可以在app1中打开app2.
打开之后,会调用app2的AppDelegate的
由于URL是自己定义的,所以会存在URL重复的情况。经过测试发现,如果试图打开这个URL,那么会打开先安装的那个应用。
数据格式化输出 1000000 -> 1,000,000
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *numberString = [numberFormatter stringFromNumber:@(1000000)];
_salesCountLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Yesterday you sold %@ apps", nil), numberString];
2.
方式一:跳转打开
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
方式二:应用内打开
通过Modal view方式弹出App Store商品详情页面。我按照文档说明,写了个例子。部分代码如下:
- (void)openAppWithIdentifier:(NSString *)appId { SKStoreProductViewController *storeProductVC = [[SKStoreProductViewController alloc] init]; storeProductVC.delegate = self; NSDictionary *dict = [NSDictionary dictionaryWithObject:appId forKey:SKStoreProductParameterITunesItemIdentifier]; [storeProductVC loadProductWithParameters:dict completionBlock:^(BOOL result, NSError *error) { if (result) { [self presentViewController:storeProductVC animated:YES completion:nil]; } }]; }
另外,需要实现SKStoreProductViewControllerDelegate如下代理方法:
#pragma mark - SKStoreProductViewControllerDelegate - (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController { [viewController dismissViewControllerAnimated:YES completion:^{ [viewController release]; }]; }
可以这样调用:
[self openAppWithIdentifier:@"383037733"];
这段代码即实现了上面图示的效果。
注:项目需要添加StoreKit框架,仅在iOS 6.0以上的设备中支持上述实现。
Framework /System/Library/Frameworks/StoreKit.framework Availability Available in iOS 6.0 and later.
如果需要兼容6.0以下的设备,可以使用下面的代码(这种方式会跳出当前应用):
- (void)outerOpenAppWithIdentifier:(NSString *)appId { NSString *urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/us/app/id%@?mt=8", appId]; NSURL *url = [NSURL URLWithString:urlStr]; [[UIApplication sharedApplication] openURL:url]; } -——————————————————————————————
-——————————————————————————————
3.
iOS 应用中打开其他应用 (转)
我们来讨论一下,在iOS开发中,如何实现从app1打开app2。基本的思路就是,可以为app2定义一个URL,在app1中通过打开这个URL来打开app2,在此过程中,可以传送一些参数。下面来讨论一下具体的实现过程。
2. 在app1的代码中打开刚才定义的URL,代码如下:
NSURL *url = [NSURL URLWithString:@"myapp://test?para1=1¶2=2"]; [[UIApplication sharedApplication] openURL:url];
当然,这个URL的形式可以是其他形式的,只要以"myapp://"开始即可。
这样,就可以在app1中打开app2.
打开之后,会调用app2的AppDelegate的
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
由于URL是自己定义的,所以会存在URL重复的情况。经过测试发现,如果试图打开这个URL,那么会打开先安装的那个应用。
相关文章推荐
- iOS开发调试技巧总结(不断更新)
- ios学习--iphone开发笔记和技巧总结(原址持续更新)
- iOS开展-Xcode技巧总结(持续更新)
- IOS 学习总结(不断更新中)
- ios学习--iphone开发笔记和技巧总结(原址持续更新)
- iOS开发调试技巧总结(持续更新中)
- C和C++语言编程里面常用函数或者编程技巧总结(不断更新)
- iOS开发调试技巧总结(持续更新中)
- javascript使用技巧总结,不断更新...
- 【不断更新贴】总结编程的技巧、语法等,需要多敲代码、记忆掌握
- iOS开发调试技巧总结(持续更新中)
- ios开发总结:Utils常用方法等收集,添加扩展类,工具类方法,拥有很多方便快捷功能(不断更新中。。。)
- ios开发总结,日常开发:ios开发功能收集,经验分享等等(不断更新中。。。)
- iOS开发调试技巧总结(持续更新中)
- Vim 技巧总结(不断更新中)
- git 使用经验与技巧总结 (不断更新中)
- linux应用技巧总结(不断更新)
- Oracle技巧总结(不断更新)
- iOS开发调试技巧总结(持续更新中)
- ListView控件使用技巧汇总(不断更新)