发布

打包

使用最新的Xcode打包IPA即可,导出时选择企业证书导出,不再赘述。

生成Plist文件

Xcode6之后使用企业证书打包仅生成IPA文件,不再自动生成Plist文件,因此需要手工生成Plist,Plist文件主要用于后续的更新操作,其范例代码如下:

<plist version="1.0">
	<dict>
		<key>items</key>
		<array>
			<dict>
				<key>assets</key>
				<array>
					<dict>
						<key>kind</key>
						<string>software-package</string>
						<key>url</key>
						<string>
							<![CDATA[
							https://xxx/xxx/xxxxx.ipa
							]]>
						</string>
					</dict>
					<dict>
						<key>kind</key>
						<string>display-image</string>
						<key>url</key>
						<string>
							https://xxx/xxxxx/xxx.png
						</string>
					</dict>
					<dict>
						<key>kind</key>
						<string>full-size-image</string>
						<key>url</key>
						<string>
							https://xxxxx/xxx/xx/xxxx.png
						</string>
					</dict>
				</array>
				<key>metadata</key>
				<dict>
					<key>bundle-identifier</key>
					<string>xxx.xxx.xx</string>
					<key>bundle-version</key>
					<string>1.0.0</string>
					<key>kind</key>
					<string>software</string>
					<key>title</key>
					<string>App Name</string>
				</dict>
			</dict>
		</array>
	</dict>
</plist>

更新

因为企业版发布避开了AppStore的审核机制,所以可以随意的在应用内加上检测更新的按钮而不用担心审核被拒,通过比对Plist文件中bundle-version与本地CFBundleShortVersionString的值,即可做出更新判断,引导用户进行更新,代码如下:

/**
 * 检查系统更新
 *
 * @param sender 检查更新按钮
 */
- (IBAction)checkUpdate:(id)sender{

    //PlistPath是你的Plist文件的位置,如http://xxx.xxx.xxx/xxx.plist
    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:PlistPath]];

    if (dict) {

        NSArray* list = [dict objectForKey:@"items"];
        NSDictionary* dict2 = [list objectAtIndex:0];

        NSDictionary* dict3 = [dict2 objectForKey:@"metadata"];
        NSString* newVersion = [dict3 objectForKey:@"bundle-version"];

        NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
        NSString *myVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];

        if (![newVersion isEqualToString:myVersion]) {
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:@"有新版本"
                                                           delegate:self
                                                  cancelButtonTitle:@"马上去更新"
                                                  otherButtonTitles:@"暂不更新", nil];
            [alert show];
        }
        else{
            UIAlertView * aler = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:@"您已经是最新版"
                                                           delegate:self
                                                  cancelButtonTitle:@"确定"
                                                  otherButtonTitles:nil, nil];
            [aler show];
        }
    }
    else{
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                        message:@"请稍后再试"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil, nil];
        [alert show];
    }
}

弹出的UIAlertView的代理方法:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex ==0) {
        //DownloadPath是你的IPA文件的位置,如http://xxx.xxx.xxx/xxx.ipa
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:DownloadPath]];
    }
    else if(buttonIndex ==1){
        NSLog(@"不更新");
    }
}

iOS9中安装企业证书的信任机制有所改变,首次安装企业版APP时要到"设置"—"通用"—"描述文件"中找到对应的企业证书,然后手动选择信任选项,才能顺利安装企业版App