zoukankan      html  css  js  c++  java
  • ios 技巧总结(不断更新)

    1.  数据格式化输出   1000000 -> 1,000,000

    1. 数据格式化输出   1000000 -> 1,000,000
    2. NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; 
    3. [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; 
    4. NSString *numberString = [numberFormatter stringFromNumber:@(1000000)]; 
    5. _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,那么会打开先安装的那个应用。

  • 相关阅读:
    多线程09-Lock和Condition
    多线程08-Callable和Future
    多线程07-线程池
    在linux环境下搭建java web测试环境(非常详细!)
    Linux下的环境部署和项目发布
    Linux下安装软件命令详解
    Linux下安装Tomcat服务器和部署Web应用
    monkey实战--测试步骤、常用参数、常规monkey命令
    如何做好回归测试
    Apache转发到Tomcat
  • 原文地址:https://www.cnblogs.com/lee4519/p/4159607.html
Copyright © 2011-2022 走看看