Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch 通过推送通知服务添加图像?_Cocoa Touch_Sqlite_Iphone Sdk 3.0_Push Notification - Fatal编程技术网

Cocoa touch 通过推送通知服务添加图像?

Cocoa touch 通过推送通知服务添加图像?,cocoa-touch,sqlite,iphone-sdk-3.0,push-notification,Cocoa Touch,Sqlite,Iphone Sdk 3.0,Push Notification,我有一个内容应用程序,希望通过苹果推送通知服务通知用户新内容,绕过现在很长的应用程序商店提交。一旦用户收到通知,下载更新按钮将启用。用户将从我的网站下载sql文件和图像。sql文件将执行insert语句,图像将下载到磁盘 我当前加载内容字符串并将图像引用捆绑到UIWebView中。图像作为内容的一部分显示。如何执行sql文件以插入新内容?那么,我是否还需要开始引用磁盘上的图像,而不是从捆绑包(我在使用App Store更新提交时将图像放在捆绑包中)中的图像 对于sql文件,我可能可以在下载完成后

我有一个内容应用程序,希望通过苹果推送通知服务通知用户新内容,绕过现在很长的应用程序商店提交。一旦用户收到通知,下载更新按钮将启用。用户将从我的网站下载sql文件和图像。sql文件将执行insert语句,图像将下载到磁盘

我当前加载内容字符串并将图像引用捆绑到UIWebView中。图像作为内容的一部分显示。如何执行sql文件以插入新内容?那么,我是否还需要开始引用磁盘上的图像,而不是从捆绑包(我在使用App Store更新提交时将图像放在捆绑包中)中的图像


对于sql文件,我可能可以在下载完成后运行一些基于事件的代码。但是需要重新加载只读数据库才能看到新内容。用户是否需要重新启动应用程序?

正如您所说,数据库对您的应用程序是只读的,我只需要让APN触发新数据库文件的下载并将其写入磁盘,而不必执行SQL语句来修改现有数据库。除非您的数据库非常大,并且您只做了一个小的更改,否则下载大小将是一个考虑因素

在任何情况下,如果您从捆绑包加载数据库,它将是只读的,因此您无法对其执行insert语句-您将需要创建一个可写副本。让更新过程全部替换此副本意味着您不必担心SQL在每个设备上正确执行。e、 g.如果应用程序在插入过程中终止,会发生什么


同样,对于图像,如果在第一次启动时将它们复制到可写图像目录,而不是从捆绑包中加载,那么您的生活会更轻松,因此您总是在同一个位置查找它们,而不在乎是否有更新。只需确保在更新后清理掉不再需要的任何东西,这样您就不会占用用户超过需要的存储空间。

当然,您可以这样做

在我的例子中,在推送通知负载中添加一些自定义字段, “msgId”可以显示您需要的字段

$body = array();
$body['device_tokens'] = str_replace(' ', '', $_REQUEST["Token"]);
$body['msgId'] = $MP_ID;
$body['aps'] = array('alert' => $alertShort);
$payload = json_encode($body);
根据您的情况,将有效负载发送到APN服务器沙盒服务器/官方服务器

添加代码以接收APN

    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
      NSLog(@"I got notification");

      [NSThread detachNewThreadSelector:@selector(handleRemoteNotification:) toTarget:self withObject:userInfo];
     }


- (void)handleRemoteNotification:(NSDictionary *)userInfo {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  [UIApplication sharedApplication].applicationIconBadgeNumber++;// = [[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] integerValue];

      if ([userInfo objectForKey:@"msgId"]) {
          iRetrievingAPNMessage++;
          NSString *msgId = [[NSString alloc] initWithString:[userInfo objectForKey:@"msgId"]];
          NSMutableString *theURL = [[NSMutableString alloc] init];
          [theURL appendFormat:@"http://yourDATAFeedPROGRAM.php?msgID=%@",msgId];

          MIPFileConnection *APNMsgConnection = [[MIPFileConnection alloc] initWithTargetURL:theURL useCache:NO];
          APNMsgConnection.delegate = self;
          [APNMsgConnection start];

          NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
          do {
          } while ((iRetrievingAPNMessage > 0) &&
                   [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
          NSLog(@"done");
      }
      [pool release];
  }

  - (void)updateDB:(NSDictionary *)msgDic {
      // do anything to update your sql db.
      // ATTENTION, the files located in bundle cannot be replaced.
      // so you need to duplicate your sql into cache/document path.
      // then you can update it successfully.
  }


  -(void)connectionDidFinishLoading:(NSURLFileConnection *)connection {
      CFPropertyListRef plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, (CFDataRef)connection.receiveData, kCFPropertyListImmutable, NULL);

          if (plist) {
              NSDictionary *tmpDic = (NSDictionary *)plist;

              [self performSelectorOnMainThread:@selector(updateDB:) withObject:[tmpDic copy] waitUntilDone:NO];

              [tmpDic release];
          }
          iRetrievingAPNMessage--;
  }
我在updateDB中使用了伪代码和伪URL,请用您的测试web URL替换它。上面的动作很有效,我做得很好。但当我的应用程序处于后台时,我无法强制通知显示图像