0

我是 iOS 和推送通知的新手。我的 PNS 在开发模式下运行良好,现在我想将其用于生产目的。

请指导我在生产模式下执行的所有程序。另外,我如何测试在生产模式下是否收到推送通知。??

Belo 代码在开发模式下运行良好...

#pragma mark - Push Notifications Methods

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSString *tokenStr = [deviceToken description];

    // Separete Your device token with <,< and blanksapace
    NSString *pushToken = [[[tokenStr
                              stringByReplacingOccurrencesOfString:@"<"  withString:@""]
                              stringByReplacingOccurrencesOfString:@">"  withString:@""]
                              stringByReplacingOccurrencesOfString:@" "  withString:@""];

    sclass.deviceToken = pushToken;
    // Save the token to server
    NSString *urlStr = [NSString stringWithFormat:@"http://www.vijaywebsolutions.com/Development_FTP/webservice/webservices.php?deviceToken=%@",pushToken]; // Passing token to URL
    NSURL *url = [NSURL URLWithString:urlStr];
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; // Support to perform URLrequest

    if( theConnection )// checking connection successfull or not
    {
        webData = [NSMutableData data];
        NSLog(@"device token is %@", pushToken);
    }
}

 - (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo 
{
    if (application.applicationState == UIApplicationStateActive) // If app is running and you got notification then show it 
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Did receive a Remote Notification" message:[NSString stringWithFormat:@"You Have a Notification :\n%@",userInfo[@"aps"][@"alert"]]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }

    NSLog(@"Payload: %@", userInfo);
    imageURL =  userInfo[@"aps"][@"alert"];
    MainViewController *MvC=[[MainViewController alloc]initWithNibName:@"MainViewControlleripad" bundle:nil];
    self.window.rootViewController=MvC;
    [MvC  sshowansimage:imageURL];
}
4

2 回答 2

2

为了测试生产推送通知服务,请在配置文件中为您的应用程序创建一个 Adhoc 分发配置文件。下载配置文件并安装。选择 Adhoc dist 配置文件以对您的应用程序进行代码签名。存档 ipa 并保存以供临时分发。将 ipa 添加到您的设备并测试推送。它将使用生产推送证书而不是开发证书。

要创建生产推送证书,您遵循与开发完全相同的程序,但您在 Apple 开发门户中选择生产(非沙盒)证书。

于 2013-11-08T11:17:10.897 回答
2

您需要分布式配置文件来测试产品模式。Product -> Archive -> Distribute -> Save for enterprise or Ad hoc -> 下一步并选择分布式配置文件。然后安装 ipa 文件。只有当您的 iphone 已越狱时,您才能执行此操作。

如果没有,如果您通过了开发模式测试,则无需担心产品模式。只需将 apns url 替换为产品模式即可。

于 2013-11-08T11:24:08.983 回答